summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig31
1 files changed, 31 insertions, 0 deletions
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, .{