From 371b2451a091954c88db3acbd070a6b0c12e1d1d Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Thu, 19 Feb 2026 15:06:09 -0300 Subject: ez --- src/main.zig | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 8192432..6c9fb8f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -162,6 +162,24 @@ pub fn main() !void { }, }, }); + // Bash tool + try jw.write(.{ + .type = "function", + .function = .{ + .name = "Bash", + .description = "Execute a shell command", + .parameters = .{ + .type = "object", + .properties = .{ + .command = .{ + .type = "string", + .description = "The command to execute", + }, + }, + .required = &[_][]const u8{"command"}, + }, + }, + }); try jw.endArray(); try jw.endObject(); @@ -240,6 +258,19 @@ pub fn main() !void { } try std.fs.cwd().writeFile(.{ .sub_path = file_path, .data = content }); result_owned = try allocator.dupe(u8, "OK"); + } else if (std.mem.eql(u8, func_name, "Bash")) { + const args_parsed = try std.json.parseFromSlice(std.json.Value, allocator, arguments_str, .{}); + defer args_parsed.deinit(); + const command = args_parsed.value.object.get("command").?.string; + std.debug.print("Running command: {s}\n", .{command}); + const result = try std.process.Child.run(.{ + .allocator = allocator, + .argv = &.{ "sh", "-c", command }, + }); + defer allocator.free(result.stdout); + defer allocator.free(result.stderr); + // Combine stdout + stderr into the tool result + result_owned = try std.fmt.allocPrint(allocator, "{s}{s}", .{ result.stdout, result.stderr }); } try messages.append(allocator, .{ -- cgit v1.2.3