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
8 changes: 7 additions & 1 deletion lua/vectorcode/integrations/codecompanion/files_ls_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ Retrieve a list of files that have been added to the database for a given projec
properties = {
project_root = {
type = "string",
description = "The project for which the indexed files will be listed. Leave this empty for the current project.",
description = [[
The project that the files belong to.
The value should be one of the following:
- One of the paths from the `vectorcode_ls` tool;
- User input;
- `null` (omit this parameter), which means the current project, if found.
]],
},
},
},
Expand Down
29 changes: 13 additions & 16 deletions lua/vectorcode/integrations/codecompanion/files_rm_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local default_opts = {
include_in_toolbox = false,
}

---@alias FilesRmArgs { paths: string[], project_root: string }
---@alias FilesRmArgs { paths: string[], project_root: string? }

---@param opts VectorCode.CodeCompanion.FilesRmToolOpts
---@return CodeCompanion.Tools
Expand Down Expand Up @@ -37,11 +37,16 @@ return function(opts)
},
project_root = {
type = "string",
description = "The project that the files belong to. Either use a path from the `vectorcode_ls` tool, or leave empty to use the current git project. If the user did not specify a path, use empty string for this parameter.",
description = [[
The project that the files belong to.
The value should be one of the following:
- One of the paths from the `vectorcode_ls` tool;
- User input;
- `null` (omit this parameter), which means the current project, if found.
]],
},
},
required = { "paths", "project_root" },
additionalProperties = false,
required = { "paths" },
},
strict = true,
},
Expand All @@ -52,25 +57,17 @@ return function(opts)
---@return nil|{ status: string, data: string }
function(tools, action, _, cb)
local args = { "files", "rm", "--pipe" }
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root or ""))
if project_root ~= "" then
if action.project_root then
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
local stat = vim.uv.fs_stat(project_root)
if stat and stat.type == "directory" then
vim.list_extend(args, { "--project_root", project_root })
else
return { status = "error", data = "Invalid path " .. project_root }
end
else
project_root = vim.fs.root(".", { ".vectorcode", ".git" }) or ""
if project_root == "" then
return {
status = "error",
data = "Please specify a project root. You may use the `vectorcode_ls` tool to find a list of existing projects.",
}
end
end
if project_root ~= "" then
action.project_root = project_root
if action.paths == nil or #action.paths == 0 then
return { status = "error", data = "Please specify at least one path." }
end
vim.list_extend(
args,
Expand Down
38 changes: 23 additions & 15 deletions lua/vectorcode/integrations/codecompanion/query_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local logger = vc_config.logger

local job_runner = nil

---@alias QueryToolArgs { project_root:string, count: integer, query: string[], allow_summary: boolean, deduplicate: boolean }
---@alias QueryToolArgs { project_root:string?, count: integer?, query: string[], allow_summary: boolean?, deduplicate: boolean? }

---@type VectorCode.CodeCompanion.QueryToolOpts
local default_query_options = {
Expand Down Expand Up @@ -259,7 +259,7 @@ local function generate_summary(result, summarise_opts, cmd, callback)

if
summarise_opts.enabled
and cmd.allow_summary
and cmd.allow_summary ~= false
and type(callback) == "function"
and #result > 0
then
Expand Down Expand Up @@ -365,6 +365,10 @@ return check_cli_wrap(function(opts)
action
)

if action.deduplicate == nil then
action.deduplicate = opts.no_duplicate
end

job_runner = cc_common.initialise_runner(opts.use_lsp)
assert(job_runner ~= nil, "Jobrunner not initialised!")
assert(
Expand All @@ -381,15 +385,15 @@ return check_cli_wrap(function(opts)

local args = { "query" }
vim.list_extend(args, action.query)
vim.list_extend(args, { "--pipe", "-n", tostring(action.count) })
vim.list_extend(
args,
{ "--pipe", "-n", tostring(action.count or opts.default_num) }
)
if opts.chunk_mode then
vim.list_extend(args, { "--include", "path", "chunk" })
else
vim.list_extend(args, { "--include", "path", "document" })
end
if action.project_root == "" then
action.project_root = nil
end
if action.project_root ~= nil then
action.project_root = vim.fs.normalize(action.project_root)
if
Expand Down Expand Up @@ -516,14 +520,20 @@ If a query returned empty or repeated results, you should avoid using these quer
count = {
type = "integer",
description = string.format(
"Number of documents or chunks to retrieve, must be positive. Use %d by default. Do not query for more than %d.",
"Number of documents or chunks to retrieve, must be positive. The default value of this parameter is %d. Do not query for more than %d results.",
tonumber(opts.default_num),
tonumber(opts.max_num)
),
},
project_root = {
type = "string",
description = "Project path to search within (must be from 'ls' results or user instructions). Use empty string for the current project. If the user did not specify a project, assume that they're referring to the current project and use an empty string for this parameter. If this fails, use the `vectorcode_ls` tool and ask the user to clarify the project.",
description = [[
The project that the files belong to.
The value should be one of the following:
- One of the paths from the `vectorcode_ls` tool;
- User input;
- `null` (omit this parameter), which means the current project, if found.
]],
},
allow_summary = {
type = "boolean",
Expand All @@ -544,14 +554,8 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
},
required = {
"query",
"count",
"project_root",
"allow_summary",
"deduplicate",
},
additionalProperties = false,
},
strict = true,
},
},
output = {
Expand Down Expand Up @@ -619,7 +623,11 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
return process_result(res)
end)
:totable()),
string.format("**VectorCode Tool**: Retrieved %d %s(s)", stdout.count, mode)
string.format(
"**VectorCode `query` Tool**: Retrieved %d %s(s)",
stdout.count,
mode
)
)
if not opts.chunk_mode then
for _, result in pairs(stdout.raw_results) do
Expand Down
33 changes: 13 additions & 20 deletions lua/vectorcode/integrations/codecompanion/vectorise_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local cc_common = require("vectorcode.integrations.codecompanion.common")
local vc_config = require("vectorcode.config")
local logger = vc_config.logger

---@alias VectoriseToolArgs { paths: string[], project_root: string }
---@alias VectoriseToolArgs { paths: string[], project_root: string? }

---@alias VectoriseResult { add: integer, update: integer, removed: integer }

Expand Down Expand Up @@ -56,13 +56,17 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
},
project_root = {
type = "string",
description = "The project that the files belong to. Either use a path from the `vectorcode_ls` tool, or leave empty to use the current git project. If the user did not specify a path, use empty string for this parameter.",
description = [[
The project that the files belong to.
The value should be one of the following:
- One of the paths from the `vectorcode_ls` tool;
- User input;
- `null` (omit this parameter), which means the current project, if found.
]],
},
},
required = { "paths", "project_root" },
additionalProperties = false,
required = { "paths" },
},
strict = true,
},
},
cmds = {
Expand All @@ -71,25 +75,14 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
---@return nil|{ status: string, data: string }
function(tools, action, _, cb)
local args = { "vectorise", "--pipe" }
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root or ""))
if project_root ~= "" then
if action.project_root then
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
local stat = vim.uv.fs_stat(project_root)
if stat and stat.type == "directory" then
vim.list_extend(args, { "--project_root", project_root })
else
return { status = "error", data = "Invalid path " .. project_root }
end
else
project_root = vim.fs.root(".", { ".vectorcode", ".git" }) or ""
if project_root == "" then
return {
status = "error",
data = "Please specify a project root. You may use the `vectorcode_ls` tool to find a list of existing projects.",
}
end
end
if project_root ~= "" then
action.project_root = project_root
end
if
vim.iter(action.paths):any(function(p)
Expand Down Expand Up @@ -139,7 +132,7 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
stderr = cc_common.flatten_table_to_string(stderr)
tools.chat:add_tool_output(
self,
string.format("**VectorCode Vectorise Tool: %s", stderr)
string.format("**VectorCode `vectorise` Tool: %s", stderr)
)
end,
---@param self CodeCompanion.Tools.Tool
Expand All @@ -151,7 +144,7 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
tools.chat:add_tool_output(
self,
string.format(
[[**VectorCode Vectorise Tool**:
[[**VectorCode `vectorise` Tool**:
- New files added: %d
- Existing files updated: %d
- Orphaned files removed: %d
Expand Down
Loading