summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-05-27 07:30:51 -0600
committerT <t@tjp.lol>2026-05-27 07:34:46 -0600
commit75fd7d7833052383e1b61d4275d12c9a993c02d3 (patch)
treee63f25a697cac215281afe76e71892a69af23cb2 /src/main.zig
parenteddebe4e8131b7d2112b067fed07e7493d8b1984 (diff)
separate event for providing tool details
OpenAI and Anthropic have tool details (id, name) converge on different timelines. In all cases they are available in `onBlockComplete` which comes with the full block, and previously we had an optional `BlockMeta` argument to `onBlockStart` - the anthropic timeline. We removed the `BlockMeta` from `onBlockStart` since it was always going to be unreliable, and now have an explicit `onToolDetails` instead. This allows us to provide the tool id and name as early as possible from the openai provider (could be in the middle of content deltas), and provide a reliable signal across providers. Also, fix test output.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index c1212e8..15b2dd2 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -10,6 +10,15 @@ const extension_loader = @import("extension_loader.zig");
const lua = lua_bridge.c;
test {
+ // Test contract: deliberate error-path tests should not produce visible
+ // log output. Code logs at `.err` for genuine production failures and
+ // `.warn` for expected-failure paths exercised by tests; the test
+ // runner's logger gates on `std.testing.log_level`, which defaults to
+ // `.warn`. Raising it to `.err` silences expected warnings without
+ // changing production behavior. Anything that *should* be visible in a
+ // passing test must use `std.debug.print` or assert via the testing API.
+ std.testing.log_level = .err;
+
std.testing.refAllDecls(@This());
_ = lua_bridge;
_ = lua_runtime;
@@ -34,12 +43,29 @@ const CLIReceiver = struct {
const vtable: ReceiverVTable = .{
.onMessageStart = onMessageStart,
.onBlockStart = onBlockStart,
+ .onToolDetails = onToolDetails,
.onContentDelta = onContentDelta,
.onBlockComplete = onBlockComplete,
.onMessageComplete = onMessageComplete,
.onError = onError,
};
+ /// The print-based CLI defers tool-name rendering to onBlockComplete
+ /// to avoid cursor gymnastics (we can't go back and edit the prefix).
+ /// Receivers backed by a TUI capable of in-place updates would render
+ /// the name as soon as it's known here.
+ fn onToolDetails(
+ ptr: *anyopaque,
+ index: usize,
+ id: []const u8,
+ name: []const u8,
+ ) anyerror!void {
+ _ = ptr;
+ _ = index;
+ _ = id;
+ _ = name;
+ }
+
fn onMessageStart(ptr: *anyopaque, role: MessageRole) anyerror!void {
_ = ptr;
_ = role;