Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129"""Record the store a reference daemon writes, for compatibility tests.
Runs two turns on the reference build that test/reference-daemon.sh pins: onethat calls Python and one that answers, each reporting usage. It then changesAGENTS.md and reloads, so the session pins the prompt its turns used, and leaves three inputs waiting in asecond session's inbox (the first carrying an image) by refusing theirtranscript rows while they are submitted. Then it stops the daemon and writesa compacted copy of its store, without that refusal, toapps/albedo/test/fixtures/reference-store/albedo.sqlite. Tests read that copyas a store an older release left behind, so current code is never what wroteit. Re-record only when the reference pin moves, and say why in the commit.
Run from the repository root inside `nix develop`:`python3 test/manual/record_reference_store.py`."""
import base64import jsonimport shutilimport sqlite3import sysfrom pathlib import Path
ROOT = Path(__file__).resolve().parents[2]OUT = ROOT / "apps/albedo/test/fixtures/reference-store/albedo.sqlite"
def main() -> None: sys.path.insert(0, str(ROOT / "e2e")) from harness import ( Albedo, Daemon, Provider, Reply, latest_user, on_daemon, operation_id, text, ) from image_limits_test import png from reference_support import run_reference
daemon = Daemon("reference-store") daemon.env["ALBEDO_STANDBY"] = "0" run_reference(daemon)
usage = { "first question": {"input_tokens": 100, "output_tokens": 20}, "second question": {"input_tokens": 300, "output_tokens": 40}, }
def reply(request): items = request.get("input", []) asked = latest_user(request) if items and items[-1].get("type") == "function_call_output": return text("ran it", usage=usage["first question"]) if asked == "first question": return Reply("python", "print(1)", usage=usage["first question"]) return text("answered", usage=usage.get(asked))
provider = Provider(reply) daemon.boot() try: with on_daemon(daemon), Albedo(provider, protocol="responses") as app: agents = app.workspace / "AGENTS.md" agents.write_text("FIRST_VERSION\n") session = app.session() for prompt in ("first question", "second question"): app.prompt(session, prompt).close() app.idle(session) # The session's pinned prompt, beside the known one its turns saved. agents.write_text("SECOND_VERSION\n") app.api(f"/sessions/{session}/reload", {"target": "session"}).close()
waiting = app.session() database = app.home / "albedo.sqlite" with sqlite3.connect(database) as db: db.execute( "CREATE TRIGGER hold_inputs BEFORE INSERT ON transcript" f" WHEN NEW.row_class='user' AND NEW.session='{waiting}'" " BEGIN SELECT RAISE(ABORT,'held for the fixture'); END" ) # Operation ids sort opposite to the order the inputs arrive in. inputs = sorted((operation_id() for _ in range(3)), reverse=True) image = base64.b64encode(png(2, 2)).decode() for input_id, intent in zip( inputs, ( { "kind": "message", "text": "waited in the old table", "images": [{"mime_type": "image/png", "data": image}], }, {"kind": "message", "text": "second old input"}, {"kind": "message", "text": "third old input"}, ), ): path = f"/sessions/{waiting}/inputs/{input_id}" with app.api(path, intent, method="PUT") as response: assert json.load(response)["delivery"] == "pending"
def copy(_app): OUT.parent.mkdir(parents=True, exist_ok=True) OUT.unlink(missing_ok=True) with sqlite3.connect(app.home / "albedo.sqlite") as db: db.execute("VACUUM INTO ?", (str(OUT),)) # One small page per table keeps the committed copy small. copied = sqlite3.connect(OUT) copied.execute("DROP TRIGGER hold_inputs") copied.execute("PRAGMA journal_mode=delete") copied.execute("PRAGMA page_size=512") copied.execute("VACUUM") copied.close()
app.restart(prepare=copy) finally: provider.close() daemon.shutdown() daemon.discard() shutil.rmtree(OUT.parent / "__pycache__", ignore_errors=True) print( f"{OUT} ({OUT.stat().st_size} bytes), session {session}," f" waiting session {waiting}, inputs {inputs}" )
if __name__ == "__main__": main()