diff options
| author | Lucas Faria Mendes <dsn.lucas@proton.me> | 2026-02-19 18:06:09 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <dsn.lucas@proton.me> | 2026-02-19 18:06:09 +0000 |
| commit | 371b2451a091954c88db3acbd070a6b0c12e1d1d (patch) | |
| tree | ee792f6fefda66b5bdf954c96ead8ade4f18b0b5 | |
| parent | 9c51912e1c0905e36001fd137631b591940364a7 (diff) | |
| download | claude-zig-371b2451a091954c88db3acbd070a6b0c12e1d1d.tar.gz claude-zig-371b2451a091954c88db3acbd070a6b0c12e1d1d.zip | |
ezmain
| -rw-r--r-- | src/main.zig | 31 |
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, .{ |