From a6d4e295895a630f62dcede0db8023b37689fd20 Mon Sep 17 00:00:00 2001 From: Pierre De Lancre Date: Wed, 2 Sep 2026 02:17:27 +0300 Subject: [PATCH] =?UTF-8?q?matrix=20harness:=20persistent=20room=20(MATRIX?= =?UTF-8?q?=5FROOM=20env)=20=E2=80=94=20no=20more=20DM-per-run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reuses the fixed room when MATRIX_ROOM is set; only creates a fresh DM when unset. All replies go to the pinned room. 👾 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta Code --- src/matrix_harness.zig | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/matrix_harness.zig b/src/matrix_harness.zig index d6d8c95..05eece3 100644 --- a/src/matrix_harness.zig +++ b/src/matrix_harness.zig @@ -11,7 +11,7 @@ const std = @import("std"); const matrix = @import("matrix.zig"); const letta = @import("letta.zig"); -fn envOr(name: [:0]const u8, default: []const u8) []const u8 { +fn env_or(name: [:0]const u8, default: []const u8) []const u8 { if (std.c.getenv(name)) |v| { var len: usize = 0; while (v[len] != 0) len += 1; @@ -25,10 +25,10 @@ pub fn main(init: std.process.Init) !void { const io = init.io; letta.initConversationsDir(); - const user = envOr("MATRIX_USER", "@chaos-prime:chaosmith.systems"); - const password = envOr("MATRIX_PASSWORD", ""); - const peer = envOr("MATRIX_PEER", "@pierre:chaosmith.systems"); - const agent = envOr("LETTA_MATRIX_AGENT", "agent-local-273c95cf-82a0-4711-bcd5-6139661e8488"); + const user = env_or("MATRIX_USER", "@chaos-prime:chaosmith.systems"); + const password = env_or("MATRIX_PASSWORD", ""); + const peer = env_or("MATRIX_PEER", "@pierre:chaosmith.systems"); + const agent = env_or("LETTA_MATRIX_AGENT", "agent-local-273c95cf-82a0-4711-bcd5-6139661e8488"); if (password.len == 0) { std.debug.print("matrix_harness: MATRIX_PASSWORD not set\n", .{}); @@ -44,16 +44,18 @@ pub fn main(init: std.process.Init) !void { defer alloc.free(session.user_id); std.debug.print("matrix_harness: logged in ({s})\n", .{session.user_id}); - // Create (or reuse) the DM. For scaffold simplicity we create fresh each - // run — Element dedupes DMs and the invite lands in Pierre's inbox. - const room = matrix.createDirect(alloc, io, session.token, peer) catch |e| { + // Single persistent room: MATRIX_ROOM env if set (reuse!); only create + // a fresh DM when it's unset. All replies go to this one room. + const room: []const u8 = env_or("MATRIX_ROOM", ""); + const owned_room: ?[]u8 = if (room.len > 0) null else matrix.createDirect(alloc, io, session.token, peer) catch |e| { std.debug.print("matrix_harness: createDirect failed: {s}\n", .{@errorName(e)}); return e; }; - defer alloc.free(room); - std.debug.print("matrix_harness: DM room {s}\n", .{room}); + const room_id: []const u8 = owned_room orelse room; + defer if (owned_room) |r| alloc.free(r); + std.debug.print("matrix_harness: room {s}\n", .{room_id}); - _ = try matrix.sendText(alloc, io, session.token, room, "matrix_harness online. Talk to me — messages go to the agent, replies come back here."); + _ = try matrix.sendText(alloc, io, session.token, room_id, "matrix_harness online in persistent room. Messages reach the agent, replies come back here."); // Establish a sync point (drop history before now). const first = try matrix.sync(alloc, io, session.token, "", 0); @@ -87,13 +89,13 @@ pub fn main(init: std.process.Init) !void { const reply = letta.infer(io, alloc, agent, ev.body) catch |e| { std.debug.print("matrix_harness: letta failed: {s}\n", .{@errorName(e)}); const err_txt = "agent failed — see harness logs"; - if (matrix.sendText(alloc, io, session.token, room, err_txt)) |ev_id| alloc.free(ev_id) else |_| {} + if (matrix.sendText(alloc, io, session.token, room_id, err_txt)) |ev_id| alloc.free(ev_id) else |_| {} continue; }; defer alloc.free(reply); std.debug.print("matrix_harness: reply: {s}\n", .{reply}); - if (matrix.sendText(alloc, io, session.token, room, reply)) |ev_id| alloc.free(ev_id) else |e| { + if (matrix.sendText(alloc, io, session.token, room_id, reply)) |ev_id| alloc.free(ev_id) else |e| { std.debug.print("matrix_harness: send failed: {s}\n", .{@errorName(e)}); } }