From ccdaef8e682960ecadf73d3b2df70559a0baaf56 Mon Sep 17 00:00:00 2001 From: t Date: Fri, 5 Jun 2026 11:43:29 -0600 Subject: Move session persistence into the Agent; collapse CLI plumbing The Agent now owns its Conversation and a SessionStore, and persists everything it generates as turns progress. Embedders get persistence for free; the CLI no longer drives the session log. libpanto: - Agent.init takes a SessionStore + optional Conversation to adopt (resume path). Agent owns/tears down the conversation; turn-driving methods drop the *Conversation param and operate on self.conversation. - New Agent methods: submitUserMessage (adds+persists the user prompt immediately), addSystemMessage(text, mode), runStep persists the turn on every exit path (incl. partial turns on error), compactAndPersist for the explicit /compact path. Auto-compaction persists its window via runStep's tail. - turn_persist.zig: DiskMessage mapping moved out of the CLI; reads usage off Message.usage (no per-message-usage list). System mode rides on DiskMessage.mode, derived from the System block. - NullStore is now an allocator-bearing struct (frees consumed messages per the store-consumes-messages contract). - Tests: in-memory CapturingStore round-trip + NullStore turn test. panto CLI: - Delete src/session_persist.zig. REPL is submitUserMessage + runStep. - Reorder construction: store -> registry -> agent -> bootstrap -> seed/ reconcile system prompt through the agent -> load extensions. - command.Context drops conv/session_mgr; commands reach ctx.agent. - system_prompt seed/reconcile call agent.addSystemMessage. - CLIReceiver is display-only (per_message_usage removed). Phases 3-5 of docs/pluggable-session-store.md. Behavior preserved; full build + test suite green. --- src/compaction.zig | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/compaction.zig') diff --git a/src/compaction.zig b/src/compaction.zig index a1f6e89..4ec5732 100644 --- a/src/compaction.zig +++ b/src/compaction.zig @@ -8,7 +8,6 @@ const std = @import("std"); const panto = @import("panto"); const command = @import("command.zig"); -const session_persist = @import("session_persist.zig"); /// Install the `/compact` command into `registry`. pub fn register(registry: *command.Registry) !void { @@ -23,20 +22,13 @@ pub fn register(registry: *command.Registry) !void { fn run(args: []const u8, ctx: *command.Context) anyerror!void { const extra: ?[]const u8 = if (args.len > 0) args else null; - const res = ctx.agent.compact(ctx.conv, ctx.compaction_prompt, extra) catch |err| { + const res = ctx.agent.compactAndPersist(ctx.compaction_prompt, extra) catch |err| { try ctx.stdout.print("\n[compaction failed: {s}]\n> ", .{@errorName(err)}); try ctx.stdout_file.flush(); return; }; if (res.compacted) { - try session_persist.persistCompaction( - ctx.allocator, - ctx.session_mgr, - ctx.conv, - ctx.provider_name, - ctx.model_name, - ); try ctx.stdout.print( "\n[compacted: summarized {d} message(s), kept {d} recent turn(s)]\n> ", .{ res.summarized_messages, res.kept_turns }, -- cgit v1.3