diff --git a/docs/neovim/README.md b/docs/neovim/README.md index 96e9477f..748814dd 100644 --- a/docs/neovim/README.md +++ b/docs/neovim/README.md @@ -234,8 +234,9 @@ The following are the common options that all tools supports: if you're using [fidget.nvim](https://github.com/j-hui/fidget.nvim). Default: `true` if `async_backend` is set to `"lsp"` in `setup()`. Otherwise, it'll be `false`; -- `requires_approval`: whether CodeCompanion.nvim asks for your approval before - executing the tool call. Default: `false` for `ls` and `query`; `true` for +- `require_approval_before`: whether CodeCompanion.nvim asks for your approval before + executing the tool call. _Use `requires_approval` if you're using CodeCompanion.nvim ` tool_opts = { -- NOTE: the other default opts are defined in the source code files of the tools. -- `include_in_toolbox` is here so that the extension setup works as expected. ls = { include_in_toolbox = true }, query = { include_in_toolbox = true }, - vectorise = { include_in_toolbox = true }, + vectorise = { + requires_approval = true, + require_approval_before = true, + include_in_toolbox = true, + }, files_ls = {}, - files_rm = {}, + files_rm = { require_approval_before = true, requires_approval = true }, }, tool_group = { enabled = true, collapse = true, extras = {} }, prompt_library = require("vectorcode.integrations.codecompanion.prompts.presets"), @@ -58,15 +63,32 @@ end local M = { ---@param opts VectorCode.CodeCompanion.ExtensionOpts setup = vc_config.check_cli_wrap(function(opts) + if + opts + and opts.tool_opts + and vim.iter(opts.tool_opts):any(function(_, v) + return v.requires_approval ~= nil + end) + then + vim.deprecate( + "requires_approval", + "require_approval_before", + "1.0.0", + "VectorCode", + false + ) + end opts = vim.tbl_deep_extend("force", default_extension_opts, opts or {}) opts.tool_opts = merge_tool_opts(opts.tool_opts) logger.info("Received codecompanion extension opts:\n", opts) local cc_config = require("codecompanion.config").config local cc_integration = require("vectorcode.integrations").codecompanion local cc_chat_integration = cc_integration.chat + + local interactions = cc_config.strategies or cc_config.interactions for _, sub_cmd in pairs(valid_tools) do local tool_name = string.format("vectorcode_%s", sub_cmd) - if cc_config.strategies.chat.tools[tool_name] ~= nil then + if interactions.chat.tools[tool_name] ~= nil then vim.notify( string.format( "There's an existing tool named `%s`. Please either remove it or rename it.", @@ -82,10 +104,16 @@ local M = { ) ) else - cc_config.strategies.chat.tools[tool_name] = { + local require_approval = opts.tool_opts[sub_cmd].requires_approval + or opts.tool_opts[sub_cmd].require_approval_before + + interactions.chat.tools[tool_name] = { description = string.format("Run VectorCode %s tool", sub_cmd), callback = cc_chat_integration.make_tool(sub_cmd, opts.tool_opts[sub_cmd]), - opts = { requires_approval = opts.tool_opts[sub_cmd].requires_approval }, + opts = { + requires_approval = require_approval, + require_approval_before = require_approval, + }, } logger.info(string.format("%s tool has been created.", tool_name)) end @@ -110,7 +138,7 @@ local M = { vim.inspect(included_tools) ) ) - cc_config.strategies.chat.tools.groups["vectorcode_toolbox"] = { + interactions.chat.tools.groups["vectorcode_toolbox"] = { opts = { collapse_tools = opts.tool_group.collapse }, description = "Use VectorCode to automatically build and retrieve repository-level context.", tools = included_tools, diff --git a/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua b/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua index 81e06d9e..e1b4e20d 100644 --- a/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/files_ls_tool.lua @@ -6,8 +6,6 @@ local utils = require("vectorcode.utils") local default_opts = { use_lsp = vc_config.get_user_config().async_backend == "lsp", - requires_approval = false, - include_in_toolbox = false, } ---@param opts VectorCode.CodeCompanion.FilesLsToolOpts diff --git a/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua b/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua index 3e882288..9993372b 100644 --- a/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/files_rm_tool.lua @@ -6,8 +6,6 @@ local utils = require("vectorcode.utils") local default_opts = { use_lsp = vc_config.get_user_config().async_backend == "lsp", - requires_approval = true, - include_in_toolbox = false, } ---@alias FilesRmArgs { paths: string[], project_root: string? } diff --git a/lua/vectorcode/integrations/codecompanion/ls_tool.lua b/lua/vectorcode/integrations/codecompanion/ls_tool.lua index e6f0dec6..0028fe29 100644 --- a/lua/vectorcode/integrations/codecompanion/ls_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/ls_tool.lua @@ -7,8 +7,6 @@ local logger = vc_config.logger ---@type VectorCode.CodeCompanion.LsToolOpts local default_ls_options = { use_lsp = vc_config.get_user_config().async_backend == "lsp", - requires_approval = false, - include_in_toolbox = true, } ---@param opts VectorCode.CodeCompanion.LsToolOpts|{}|nil diff --git a/lua/vectorcode/integrations/codecompanion/query_tool.lua b/lua/vectorcode/integrations/codecompanion/query_tool.lua index 0b7d10d1..59d958bd 100644 --- a/lua/vectorcode/integrations/codecompanion/query_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/query_tool.lua @@ -16,8 +16,6 @@ local job_runner = nil ---@type VectorCode.CodeCompanion.QueryToolOpts local default_query_options = { use_lsp = vc_config.get_user_config().async_backend == "lsp", - requires_approval = false, - include_in_toolbox = true, max_num = { chunk = -1, document = -1 }, default_num = { chunk = 50, document = 10 }, no_duplicate = true, diff --git a/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua b/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua index 57d396ef..9a353d82 100644 --- a/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua +++ b/lua/vectorcode/integrations/codecompanion/vectorise_tool.lua @@ -12,8 +12,6 @@ local logger = vc_config.logger ---@type VectorCode.CodeCompanion.VectoriseToolOpts local default_vectorise_options = { use_lsp = vc_config.get_user_config().async_backend == "lsp", - requires_approval = true, - include_in_toolbox = true, } ---@param opts VectorCode.CodeCompanion.VectoriseToolOpts|{}|nil diff --git a/lua/vectorcode/types.lua b/lua/vectorcode/types.lua index b2d853a8..691c572d 100644 --- a/lua/vectorcode/types.lua +++ b/lua/vectorcode/types.lua @@ -76,6 +76,7 @@ --- Whether to use the LSP backend. Default: `false` ---@field use_lsp boolean? ---@field requires_approval boolean? +---@field require_approval_before boolean? --- Whether this tool should be included in `vectorcode_toolbox` ---@field include_in_toolbox boolean?