Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/neovim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<v18.0.0`_.
Default: `false` for `ls` and `query`; `true` for
`vectorise`;
- `include_in_toolbox`: whether this tool should be included in
`vectorcode_toolbox`. Default: `true` for `query`, `vectorise` and `ls`,
Expand Down
40 changes: 34 additions & 6 deletions lua/codecompanion/_extensions/vectorcode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ local utils = require("vectorcode.utils")

---@type VectorCode.CodeCompanion.ExtensionOpts|{}
local default_extension_opts = {
---@type table<sub_cmd, VectorCode.CodeCompanion.ToolOpts|{}>
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"),
Expand Down Expand Up @@ -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.",
Expand All @@ -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
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions lua/vectorcode/integrations/codecompanion/files_ls_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lua/vectorcode/integrations/codecompanion/files_rm_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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? }
Expand Down
2 changes: 0 additions & 2 deletions lua/vectorcode/integrations/codecompanion/ls_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lua/vectorcode/integrations/codecompanion/query_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions lua/vectorcode/integrations/codecompanion/vectorise_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/vectorcode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
Loading