@@ -20,23 +20,28 @@ const bash_params =
2020 const read_description = "Read a file. Returns its text. Returns the whole file unless offset and range give a line window. Prefer bash for search or binary files.";
2121 const read_image_description = "Read a file. Returns its text, or the image itself when the file is a png, jpg, or webp. Returns the whole file unless offset and range give a line window. Prefer bash for search or binary files.";
2222 const edit_description = "Edit a file by exact text replacement. oldText must occur exactly once. With empty oldText, create a new file (fails if it exists).";
23-const bash_description = "Run a bash command in the current working directory.";
23+const bash_description = "Run a bash command in the current working directory ({s}).";
2424
2525 pub fn execute(a: std.mem.Allocator, scratch: std.mem.Allocator, name: []const u8, args_json: []const u8, ctx: common.Context) common.Result {
26- if (std.mem.eql(u8, name, "read")) return read_tool.run(a, scratch, args_json, ctx);
27- if (std.mem.eql(u8, name, "edit")) return edit_tool.run(a, scratch, args_json, ctx);
28- if (std.mem.eql(u8, name, "bash")) return bash_tool.run(a, scratch, args_json, ctx);
26+ const enabled = for (ctx.tools) |tool| {
27+ if (std.mem.eql(u8, name, @tagName(tool))) break true;
28+ } else false;
29+ if (enabled) {
30+ if (std.mem.eql(u8, name, "read")) return read_tool.run(a, scratch, args_json, ctx);
31+ if (std.mem.eql(u8, name, "edit")) return edit_tool.run(a, scratch, args_json, ctx);
32+ if (std.mem.eql(u8, name, "bash")) return bash_tool.run(a, scratch, args_json, ctx);
33+ }
2934 return .{
3035 .text = std.fmt.allocPrint(a, "unknown tool: {s}", .{name}) catch "unknown tool",
3136 .is_error = true,
3237 };
3338 }
3439
35-fn writeTool(w: *std.Io.Writer, name: config.ToolName, with_images: bool) !void {
40+fn writeTool(w: *std.Io.Writer, name: config.ToolName, with_images: bool, bash_desc: []const u8) !void {
3641 const description = switch (name) {
3742 .read => if (with_images) read_image_description else read_description,
3843 .edit => edit_description,
39- .bash => bash_description,
44+ .bash => bash_desc,
4045 };
4146 try w.writeAll("{\"name\":");
4247 try std.json.Stringify.encodeJsonString(@tagName(name), .{}, w);
@@ -51,13 +56,14 @@ fn writeTool(w: *std.Io.Writer, name: config.ToolName, with_images: bool) !void
5156 try w.writeByte('}');
5257 }
5358
54-pub fn json(a: std.mem.Allocator, names: []const config.ToolName, with_images: bool) []const u8 {
59+pub fn json(a: std.mem.Allocator, names: []const config.ToolName, with_images: bool, cwd: []const u8) []const u8 {
60+ const bash_desc = std.fmt.allocPrint(a, bash_description, .{cwd}) catch "Run a bash command in the current working directory.";
5561 var out: std.Io.Writer.Allocating = .init(a);
5662 const w = &out.writer;
5763 w.writeByte('[') catch return "[]";
5864 for (names, 0..) |name, i| {
5965 if (i > 0) w.writeByte(',') catch return out.written();
60- writeTool(w, name, with_images) catch return out.written();
66+ writeTool(w, name, with_images, bash_desc) catch return out.written();
6167 }
6268 w.writeByte(']') catch return out.written();
6369 return out.written();