From 75fd7d7833052383e1b61d4275d12c9a993c02d3 Mon Sep 17 00:00:00 2001 From: T Date: Wed, 27 May 2026 07:30:51 -0600 Subject: 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. --- src/main.zig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/main.zig') 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; -- cgit v1.3