From 02ae92d61945e19801fa07b4b60c452e80310c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Thu, 7 May 2026 10:34:14 +0200 Subject: [PATCH] agent: remove unused code and add recorder guard --- src/agent/Agent.zig | 18 ++++++++++-------- src/agent/CommandExecutor.zig | 3 --- src/agent/SlashCommand.zig | 24 +++++++++--------------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/agent/Agent.zig b/src/agent/Agent.zig index 71a6d0c8..5b31f546 100644 --- a/src/agent/Agent.zig +++ b/src/agent/Agent.zig @@ -920,15 +920,17 @@ fn processUserMessage(self: *Self, user_input: []const u8, record_comment: ?[]co }; defer result.deinit(); - var recorded_any = false; - for (result.tool_calls_made) |tc| { - if (!tc.is_error) { - if (Command.fromToolCall(ma, tc.name, tc.arguments)) |cmd| { - if (!recorded_any) { - if (record_comment) |c| self.recorder.recordComment(c); - recorded_any = true; + if (self.recorder.file != null) { + var recorded_any = false; + for (result.tool_calls_made) |tc| { + if (!tc.is_error) { + if (Command.fromToolCall(ma, tc.name, tc.arguments)) |cmd| { + if (!recorded_any) { + if (record_comment) |c| self.recorder.recordComment(c); + recorded_any = true; + } + self.recorder.record(cmd); } - self.recorder.record(cmd); } } } diff --git a/src/agent/CommandExecutor.zig b/src/agent/CommandExecutor.zig index c5aae7aa..6d64990c 100644 --- a/src/agent/CommandExecutor.zig +++ b/src/agent/CommandExecutor.zig @@ -24,7 +24,6 @@ pub const ExecResult = struct { }; pub fn executeWithResult(self: *Self, arena: std.mem.Allocator, cmd: Command.Command) ExecResult { - // EXTRACT has no 1:1 tool mapping — it compiles to a custom `eval` script. if (cmd == .extract) return self.execExtract(arena, cmd.extract); const tc = Command.toToolCall(arena, cmd, browser_tools.substituteEnvVars) orelse switch (cmd) { @@ -62,8 +61,6 @@ fn callTool(self: *Self, arena: std.mem.Allocator, tool_name: []const u8, argume fn execExtract(self: *Self, arena: std.mem.Allocator, raw_selector: []const u8) ExecResult { const selector = browser_tools.substituteEnvVars(arena, raw_selector); - // A JSON-quoted string is also a valid JS string literal, so reuse - // `buildJson` to splice the selector into the querySelectorAll call. const script = std.fmt.allocPrint( arena, "JSON.stringify(Array.from(document.querySelectorAll({s})).map(el => el.textContent.trim()))", diff --git a/src/agent/SlashCommand.zig b/src/agent/SlashCommand.zig index b045f165..5624c986 100644 --- a/src/agent/SlashCommand.zig +++ b/src/agent/SlashCommand.zig @@ -28,11 +28,6 @@ pub const SchemaInfo = struct { hints: []const HintSlot, }; -pub const Parsed = struct { - schema: *const SchemaInfo, - args_json: []const u8, -}; - pub const ParseError = error{ MissingName, UnknownTool, @@ -152,14 +147,6 @@ pub fn splitNameRest(input: []const u8) ?Split { }; } -/// Parse a slash command body (without the leading `/`). -/// `arena` is used for the resulting JSON string and any temporary storage. -pub fn parse(arena: std.mem.Allocator, schemas: []const SchemaInfo, input: []const u8) ParseError!Parsed { - const split = splitNameRest(input) orelse return error.MissingName; - const schema = findSchema(schemas, split.name) orelse return error.UnknownTool; - return .{ .schema = schema, .args_json = try parseArgs(arena, schema, split.rest) }; -} - /// Parse the args portion of a slash command for an already-resolved schema. pub fn parseArgs(arena: std.mem.Allocator, schema: *const SchemaInfo, rest: []const u8) ParseError![]const u8 { if (rest.len == 0) { @@ -315,7 +302,12 @@ fn lookupFieldType(schema: *const SchemaInfo, key: []const u8) FieldType { const testing = std.testing; -fn parseWithCache(arena: std.mem.Allocator, input: []const u8) !Parsed { +const ParsedTest = struct { + schema: *const SchemaInfo, + args_json: []const u8, +}; + +fn parseWithCache(arena: std.mem.Allocator, input: []const u8) !ParsedTest { const tools = try arena.alloc(zenai.provider.Tool, browser_tools.tool_defs.len); for (browser_tools.tool_defs, 0..) |td, i| { tools[i] = .{ @@ -325,7 +317,9 @@ fn parseWithCache(arena: std.mem.Allocator, input: []const u8) !Parsed { }; } const schemas = try buildSchemas(arena, tools); - return parse(arena, schemas, input); + const split = splitNameRest(input) orelse return error.MissingName; + const schema = findSchema(schemas, split.name) orelse return error.UnknownTool; + return .{ .schema = schema, .args_json = try parseArgs(arena, schema, split.rest) }; } fn expectParse(input: []const u8, expected_tool: []const u8, expected_json: []const u8) !void {