Skip to content

Commit 747e8a0

Browse files
authored
refactor(nvim): Relax schema requirements for CodeCompanion tools (closes #273) (#275)
* refactor(nvim): Relax schema requirements for CodeCompanion tools (#273) * chore(nvim): Update descriptions for codecompanion tools
1 parent 6504034 commit 747e8a0

File tree

4 files changed

+56
-52
lines changed

4 files changed

+56
-52
lines changed

lua/vectorcode/integrations/codecompanion/files_ls_tool.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ Retrieve a list of files that have been added to the database for a given projec
6767
properties = {
6868
project_root = {
6969
type = "string",
70-
description = "The project for which the indexed files will be listed. Leave this empty for the current project.",
70+
description = [[
71+
The project that the files belong to.
72+
The value should be one of the following:
73+
- One of the paths from the `vectorcode_ls` tool;
74+
- User input;
75+
- `null` (omit this parameter), which means the current project, if found.
76+
]],
7177
},
7278
},
7379
},

lua/vectorcode/integrations/codecompanion/files_rm_tool.lua

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local default_opts = {
99
include_in_toolbox = false,
1010
}
1111

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

1414
---@param opts VectorCode.CodeCompanion.FilesRmToolOpts
1515
---@return CodeCompanion.Tools
@@ -37,11 +37,16 @@ return function(opts)
3737
},
3838
project_root = {
3939
type = "string",
40-
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.",
40+
description = [[
41+
The project that the files belong to.
42+
The value should be one of the following:
43+
- One of the paths from the `vectorcode_ls` tool;
44+
- User input;
45+
- `null` (omit this parameter), which means the current project, if found.
46+
]],
4147
},
4248
},
43-
required = { "paths", "project_root" },
44-
additionalProperties = false,
49+
required = { "paths" },
4550
},
4651
strict = true,
4752
},
@@ -52,25 +57,17 @@ return function(opts)
5257
---@return nil|{ status: string, data: string }
5358
function(tools, action, _, cb)
5459
local args = { "files", "rm", "--pipe" }
55-
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root or ""))
56-
if project_root ~= "" then
60+
if action.project_root then
61+
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
5762
local stat = vim.uv.fs_stat(project_root)
5863
if stat and stat.type == "directory" then
5964
vim.list_extend(args, { "--project_root", project_root })
6065
else
6166
return { status = "error", data = "Invalid path " .. project_root }
6267
end
63-
else
64-
project_root = vim.fs.root(".", { ".vectorcode", ".git" }) or ""
65-
if project_root == "" then
66-
return {
67-
status = "error",
68-
data = "Please specify a project root. You may use the `vectorcode_ls` tool to find a list of existing projects.",
69-
}
70-
end
7168
end
72-
if project_root ~= "" then
73-
action.project_root = project_root
69+
if action.paths == nil or #action.paths == 0 then
70+
return { status = "error", data = "Please specify at least one path." }
7471
end
7572
vim.list_extend(
7673
args,

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local logger = vc_config.logger
1010

1111
local job_runner = nil
1212

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

1515
---@type VectorCode.CodeCompanion.QueryToolOpts
1616
local default_query_options = {
@@ -259,7 +259,7 @@ local function generate_summary(result, summarise_opts, cmd, callback)
259259

260260
if
261261
summarise_opts.enabled
262-
and cmd.allow_summary
262+
and cmd.allow_summary ~= false
263263
and type(callback) == "function"
264264
and #result > 0
265265
then
@@ -365,6 +365,10 @@ return check_cli_wrap(function(opts)
365365
action
366366
)
367367

368+
if action.deduplicate == nil then
369+
action.deduplicate = opts.no_duplicate
370+
end
371+
368372
job_runner = cc_common.initialise_runner(opts.use_lsp)
369373
assert(job_runner ~= nil, "Jobrunner not initialised!")
370374
assert(
@@ -381,15 +385,15 @@ return check_cli_wrap(function(opts)
381385

382386
local args = { "query" }
383387
vim.list_extend(args, action.query)
384-
vim.list_extend(args, { "--pipe", "-n", tostring(action.count) })
388+
vim.list_extend(
389+
args,
390+
{ "--pipe", "-n", tostring(action.count or opts.default_num) }
391+
)
385392
if opts.chunk_mode then
386393
vim.list_extend(args, { "--include", "path", "chunk" })
387394
else
388395
vim.list_extend(args, { "--include", "path", "document" })
389396
end
390-
if action.project_root == "" then
391-
action.project_root = nil
392-
end
393397
if action.project_root ~= nil then
394398
action.project_root = vim.fs.normalize(action.project_root)
395399
if
@@ -516,14 +520,20 @@ If a query returned empty or repeated results, you should avoid using these quer
516520
count = {
517521
type = "integer",
518522
description = string.format(
519-
"Number of documents or chunks to retrieve, must be positive. Use %d by default. Do not query for more than %d.",
523+
"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.",
520524
tonumber(opts.default_num),
521525
tonumber(opts.max_num)
522526
),
523527
},
524528
project_root = {
525529
type = "string",
526-
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.",
530+
description = [[
531+
The project that the files belong to.
532+
The value should be one of the following:
533+
- One of the paths from the `vectorcode_ls` tool;
534+
- User input;
535+
- `null` (omit this parameter), which means the current project, if found.
536+
]],
527537
},
528538
allow_summary = {
529539
type = "boolean",
@@ -544,14 +554,8 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
544554
},
545555
required = {
546556
"query",
547-
"count",
548-
"project_root",
549-
"allow_summary",
550-
"deduplicate",
551557
},
552-
additionalProperties = false,
553558
},
554-
strict = true,
555559
},
556560
},
557561
output = {
@@ -619,7 +623,11 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
619623
return process_result(res)
620624
end)
621625
:totable()),
622-
string.format("**VectorCode Tool**: Retrieved %d %s(s)", stdout.count, mode)
626+
string.format(
627+
"**VectorCode `query` Tool**: Retrieved %d %s(s)",
628+
stdout.count,
629+
mode
630+
)
623631
)
624632
if not opts.chunk_mode then
625633
for _, result in pairs(stdout.raw_results) do

lua/vectorcode/integrations/codecompanion/vectorise_tool.lua

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local cc_common = require("vectorcode.integrations.codecompanion.common")
44
local vc_config = require("vectorcode.config")
55
local logger = vc_config.logger
66

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

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

@@ -56,13 +56,17 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
5656
},
5757
project_root = {
5858
type = "string",
59-
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.",
59+
description = [[
60+
The project that the files belong to.
61+
The value should be one of the following:
62+
- One of the paths from the `vectorcode_ls` tool;
63+
- User input;
64+
- `null` (omit this parameter), which means the current project, if found.
65+
]],
6066
},
6167
},
62-
required = { "paths", "project_root" },
63-
additionalProperties = false,
68+
required = { "paths" },
6469
},
65-
strict = true,
6670
},
6771
},
6872
cmds = {
@@ -71,25 +75,14 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
7175
---@return nil|{ status: string, data: string }
7276
function(tools, action, _, cb)
7377
local args = { "vectorise", "--pipe" }
74-
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root or ""))
75-
if project_root ~= "" then
78+
if action.project_root then
79+
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
7680
local stat = vim.uv.fs_stat(project_root)
7781
if stat and stat.type == "directory" then
7882
vim.list_extend(args, { "--project_root", project_root })
7983
else
8084
return { status = "error", data = "Invalid path " .. project_root }
8185
end
82-
else
83-
project_root = vim.fs.root(".", { ".vectorcode", ".git" }) or ""
84-
if project_root == "" then
85-
return {
86-
status = "error",
87-
data = "Please specify a project root. You may use the `vectorcode_ls` tool to find a list of existing projects.",
88-
}
89-
end
90-
end
91-
if project_root ~= "" then
92-
action.project_root = project_root
9386
end
9487
if
9588
vim.iter(action.paths):any(function(p)
@@ -139,7 +132,7 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
139132
stderr = cc_common.flatten_table_to_string(stderr)
140133
tools.chat:add_tool_output(
141134
self,
142-
string.format("**VectorCode Vectorise Tool: %s", stderr)
135+
string.format("**VectorCode `vectorise` Tool: %s", stderr)
143136
)
144137
end,
145138
---@param self CodeCompanion.Tools.Tool
@@ -151,7 +144,7 @@ The paths should be accurate (DO NOT ASSUME A PATH EXIST) and case case-sensitiv
151144
tools.chat:add_tool_output(
152145
self,
153146
string.format(
154-
[[**VectorCode Vectorise Tool**:
147+
[[**VectorCode `vectorise` Tool**:
155148
- New files added: %d
156149
- Existing files updated: %d
157150
- Orphaned files removed: %d

0 commit comments

Comments
 (0)