From b7f5fb89099ec974cd28091a4d56253554211eaf Mon Sep 17 00:00:00 2001 From: retoor Date: Fri, 28 Mar 2025 22:11:55 +0000 Subject: [PATCH] feat: add mkdir directory creation support via vibe tool Implement the mkdir command in the vibe tool to allow users to create directories directly from the command line interface. This addition enables programmatic directory creation without requiring manual shell commands, improving workflow automation and integration capabilities within the vibe ecosystem. --- tools.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tools.h b/tools.h index c4d1436..c0d2404 100644 --- a/tools.h +++ b/tools.h @@ -48,6 +48,7 @@ struct json_object *tool_description_db_query(); struct json_object *tool_description_db_get(); struct json_object *tool_description_web_search_news(); struct json_object *tool_description_web_search(); +struct json_object *tool_description_mkdir(); struct json_object *tools_descriptions() { struct json_object *root = json_object_new_array(); @@ -66,6 +67,7 @@ struct json_object *tools_descriptions() { json_object_array_add(root, tool_description_db_get()); json_object_array_add(root, tool_description_web_search_news()); json_object_array_add(root, tool_description_web_search()); + json_object_array_add(root, tool_description_mkdir()); return root; } @@ -1042,6 +1044,52 @@ struct json_object *tool_description_linux_terminal() { return root; } +char *tool_function_mkdir(char *path) { + if (mkdir(path, 0777) != 0) { + perror("mkdir failed"); + return strdup("Failed to create directory!"); + } + return strdup("Directory successfully created."); +} + +struct json_object *tool_description_mkdir() { + struct json_object *root = json_object_new_object(); + json_object_object_add(root, "type", json_object_new_string("function")); + + struct json_object *function = json_object_new_object(); + json_object_object_add(function, "name", json_object_new_string("mkdir")); + json_object_object_add( + function, "description", + json_object_new_string("Creates a new directory with the specified path.")); + + struct json_object *parameters = json_object_new_object(); + json_object_object_add(parameters, "type", json_object_new_string("object")); + + struct json_object *properties = json_object_new_object(); + struct json_object *path = json_object_new_object(); + json_object_object_add(path, "type", json_object_new_string("string")); + json_object_object_add( + path, "description", + json_object_new_string("Path of the directory to create.")); + json_object_object_add(properties, "path", path); + + json_object_object_add(parameters, "properties", properties); + + struct json_object *required = json_object_new_array(); + json_object_array_add(required, json_object_new_string("path")); + json_object_object_add(parameters, "required", required); + + json_object_object_add(parameters, "additionalProperties", + json_object_new_boolean(0)); + + json_object_object_add(function, "parameters", parameters); + json_object_object_add(function, "strict", json_object_new_boolean(1)); + + json_object_object_add(root, "function", function); + + return root; +} + struct json_object *tools_execute(struct json_object *tools_array) { struct json_object *tools_result_messages = json_object_new_array(); int array_len = json_object_array_length(tools_array); @@ -1311,6 +1359,21 @@ struct json_object *tools_execute(struct json_object *tools_array) { free(listing_result); } } + } else if (!strcmp(function_name, "mkdir")) { + struct json_object *arguments_obj; + if (json_object_object_get_ex(function_obj, "arguments", + &arguments_obj)) { + struct json_object *arguments = + json_tokener_parse(json_object_get_string(arguments_obj)); + struct json_object *path_obj; + if (json_object_object_get_ex(arguments, "path", &path_obj)) { + char *path = (char *)json_object_get_string(path_obj); + char *mkdir_result = tool_function_mkdir(path); + json_object_object_add(tool_result, "content", + json_object_new_string(mkdir_result)); + free(mkdir_result); + } + } } else { fprintf(stderr, "Unknown function: %s\n", function_name); json_object_object_add( @@ -1325,4 +1388,3 @@ struct json_object *tools_execute(struct json_object *tools_array) { } #endif -