Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

rlm: a printed slim view says it is one (ADR 0238)

justrache7c6ebd317ef
diff --git a/docs/adr/0238-rlm-binds-keep-the-whole-mcp-result.md b/docs/adr/0238-rlm-binds-keep-the-whole-mcp-result.md
index bd4bb17b..3c59e2f0 100644
--- a/docs/adr/0238-rlm-binds-keep-the-whole-mcp-result.md
+++ b/docs/adr/0238-rlm-binds-keep-the-whole-mcp-result.md
@@ -27,9 +27,11 @@ not in the conversation: only `print()` output is.
- An MCP call from inside an rlm script (`ToolCtx.rlm_host`) binds the
tool's whole result. `exec.zig` no longer slims it.
-- `print()` still shows the slim view (`rlm.maybeSlim`). An `each()` bind,
- one whole result per item, prints each item's own cut, the view the
- per-item slim used to bind.
+- `print()` still shows the slim view (`rlm.maybeSlim`), now with one line
+ that says it is a slim view of an N-byte value that keeps every field. An
+ `each()` bind, one whole result per item, prints each item's own cut, the
+ view the per-item slim used to bind. Unmarked, a model that printed a file
+ it had just saved took the view for the file's contents.
- `project(x, field)` reads any field of a row. Over an `each()` bind of
comment lists, `n` and `latest_author` read the fold, so scripts written
against the printed view keep working.
diff --git a/src/rlm.zig b/src/rlm.zig
index f2677701..89c9cca2 100644
--- a/src/rlm.zig
+++ b/src/rlm.zig
@@ -381,7 +381,7 @@ fn renderPrintPart(ctx: ToolCtx, arena: Allocator, inner: []const u8, binds: []c
status.* = try order.copy(ctx.gpa, out);
return "";
}
- if (mcp_shapes.slim(arena, out.text)) |s| return s;
+ if (mcp_shapes.slim(arena, out.text)) |s| return slimNote(arena, s, out.text.len);
return try arena.dupe(u8, out.text);
}
// Preserve the historical missing-bind echo, but do not pretend an
@@ -397,7 +397,14 @@ fn unsupportedPrint(ctx: ToolCtx, status: *?ToolOutput) ![]const u8 {
}
fn maybeSlim(arena: Allocator, payload: []const u8) []const u8 {
- return mcp_shapes.slim(arena, payload) orelse payload;
+ const cut = mcp_shapes.slim(arena, payload) orelse return payload;
+ return slimNote(arena, cut, payload.len);
+}
+
+/// ADR 0238: a printed cut says it is one. Unsaid, a model that printed a
+/// file it had just saved took the view for the file's contents.
+pub fn slimNote(arena: Allocator, cut: []const u8, full: usize) []const u8 {
+ return std.fmt.allocPrint(arena, "{s}\n[slim view of a {d}-byte value; the value keeps every field: project(x, field) reads one, write_file saves it whole]", .{ cut, full }) catch cut;
}
fn observe(ctx: ToolCtx, call: spec_ptc.Call, out: ToolOutput) !void {
diff --git a/src/rlm_tests.zig b/src/rlm_tests.zig
index 89b1c846..c6613718 100644
--- a/src/rlm_tests.zig
+++ b/src/rlm_tests.zig
@@ -467,3 +467,11 @@ test "#1016: literal read_file stays native when an MCP short name collides" {
try std.testing.expect(std.mem.indexOf(u8, out.text, "hello-native") != null);
try std.testing.expect(std.mem.indexOf(u8, out.text, "MCP tool schema is not loaded") == null);
}
+
+test "a printed slim view names itself and the full size (ADR 0238)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const note = @import("rlm.zig").slimNote(arena_state.allocator(), "[{\"id\":\"ISS-1\"}]", 56005);
+ try std.testing.expect(std.mem.startsWith(u8, note, "[{\"id\":\"ISS-1\"}]\n[slim view of a 56005-byte value"));
+ try std.testing.expect(std.mem.indexOf(u8, note, "write_file") != null);
+}