Skip to content

Commit a9463ce

Browse files
authored
Merge pull request #1 from lattenwald/claude/review-upstream-changes-cXKcu
fix(codecompanion): add additionalProperties to tool_input of use_mcp_tool (ravitemer#264)
2 parents e2ab082 + f59044c commit a9463ce

5 files changed

Lines changed: 93 additions & 27 deletions

File tree

lua/mcphub/extensions/codecompanion/tools.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ local tool_schemas = {
113113
tool_input = {
114114
description = "Input object for the tool call",
115115
type = "object",
116+
additionalProperties = false,
116117
},
117118
},
118119
required = { "server_name", "tool_name", "tool_input" },

lua/mcphub/hub.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ function MCPHub:start()
342342

343343
-- Make sure to load after the config is refreshed to avoid double reading of config files
344344
native.setup(config.native_servers)
345+
self:fire_servers_updated()
345346

346347
-- Step 3: Check if server is already running on the resolved port and is of same version in cases of plugin updated
347348
self:check_server(function(is_running, is_our_server, is_same_version)

lua/mcphub/native/neovim/files/environment.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ return {
3333

3434
-- Format workspace files
3535
local workspace_files = vim.tbl_map(function(file)
36-
return string.format("%s (%s, %.2fKB)", file.name, file.type, file.size / 1024)
36+
if file.type == "link" and file.symlink_target then
37+
return string.format("%s (symlink -> %s, %.2fKB)", file.name, file.symlink_target, file.size / 1024)
38+
else
39+
return string.format("%s (%s, %.2fKB)", file.name, file.type, file.size / 1024)
40+
end
3741
end, dir_info.files)
3842

3943
local text = string.format(

lua/mcphub/native/neovim/utils/buffer.lua

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,61 @@ local M = {}
22

33
---@class FileInfo
44
---@field name string # File name or path
5-
---@field type string # File type (file/directory/etc)
5+
---@field type string # File type (file/directory/link/etc)
66
---@field size number # File size in bytes
77
---@field modified number # Last modification timestamp
8+
---@field symlink_target string|nil # If type is 'link', the target path
89

910
---@class DirectoryInfo
1011
---@field path string # Current directory path
1112
---@field is_git boolean # Whether the directory is a git repository
1213
---@field files FileInfo[] # List of files in the directory
1314

15+
---@param path? string # Directory path to scan (defaults to current working directory)
16+
---@return DirectoryInfo
1417
---@param path? string # Directory path to scan (defaults to current working directory)
1518
---@return DirectoryInfo
1619
function M.get_directory_info(path)
1720
path = path or vim.loop.cwd()
18-
-- Check if git repo
19-
local is_git = vim.fn.system("git rev-parse --is-inside-work-tree 2>/dev/null"):match("true")
21+
22+
-- Normalize path separators
23+
path = vim.fn.fnamemodify(path, ":p:h")
24+
25+
-- Check if the specified path is a git repo
26+
-- Use -C flag to specify directory instead of cd command for better cross-platform support
27+
local is_git = vim.fn
28+
.system(string.format("git -C %s rev-parse --is-inside-work-tree 2>/dev/null", vim.fn.shellescape(path)))
29+
:match("true")
2030
local files = {}
2131

2232
if is_git then
23-
-- Use git ls-files for git-aware listing
24-
local git_files = vim.fn.systemlist("git ls-files --cached --others --exclude-standard")
33+
-- Use git ls-files for git-aware listing in the specified directory
34+
local git_files = vim.fn.systemlist(
35+
string.format("git -C %s ls-files --cached --others --exclude-standard", vim.fn.shellescape(path))
36+
)
2537
for _, file in ipairs(git_files) do
26-
local stat = vim.loop.fs_stat(file)
27-
if stat then
28-
table.insert(files, {
38+
-- Build full path using cross-platform path joining
39+
local full_path = vim.fs.joinpath and vim.fs.joinpath(path, file) or (path .. "/" .. file)
40+
41+
-- Use lstat to detect symlinks without following them
42+
local lstat = vim.loop.fs_lstat(full_path)
43+
if lstat then
44+
local file_info = {
2945
name = file,
30-
type = stat.type,
31-
size = stat.size,
32-
modified = stat.mtime.sec,
33-
})
46+
type = lstat.type,
47+
size = lstat.size,
48+
modified = lstat.mtime.sec,
49+
}
50+
51+
-- If it's a symlink, get the target path
52+
if lstat.type == "link" then
53+
local target = vim.loop.fs_readlink(full_path)
54+
if target then
55+
file_info.symlink_target = target
56+
end
57+
end
58+
59+
table.insert(files, file_info)
3460
end
3561
end
3662
else
@@ -43,14 +69,28 @@ function M.get_directory_info(path)
4369
break
4470
end
4571

46-
local stat = vim.loop.fs_stat(name)
47-
if stat then
48-
table.insert(files, {
72+
-- Build full path using cross-platform path joining
73+
local full_path = vim.fs.joinpath and vim.fs.joinpath(path, name) or (path .. "/" .. name)
74+
75+
-- Use lstat to detect symlinks without following them
76+
local lstat = vim.loop.fs_lstat(full_path)
77+
if lstat then
78+
local file_info = {
4979
name = name,
50-
type = type or stat.type,
51-
size = stat.size,
52-
modified = stat.mtime.sec,
53-
})
80+
type = type or lstat.type,
81+
size = lstat.size,
82+
modified = lstat.mtime.sec,
83+
}
84+
85+
-- If it's a symlink, get the target path
86+
if lstat.type == "link" then
87+
local target = vim.loop.fs_readlink(full_path)
88+
if target then
89+
file_info.symlink_target = target
90+
end
91+
end
92+
93+
table.insert(files, file_info)
5494
end
5595
end
5696
end

lua/mcphub/utils/ui.lua

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,27 @@ function M.multiline_input(title, content, on_save, opts)
110110
end
111111
end
112112
-- Close the window
113-
vim.api.nvim_win_close(win, true)
113+
if vim.api.nvim_win_is_valid(win) then
114+
vim.api.nvim_win_close(win, true)
115+
end
116+
117+
if vim.api.nvim_buf_is_valid(bufnr) then
118+
vim.api.nvim_buf_delete(bufnr, { force = true })
119+
end
114120
-- -- Call save callback if content changed
115121
-- if content ~= new_content then
116122
on_save(new_content)
117123
-- end
118124
end
119125

120126
local function close_window()
121-
vim.api.nvim_win_close(win, true)
127+
if vim.api.nvim_win_is_valid(win) then
128+
vim.api.nvim_win_close(win, true)
129+
end
130+
131+
if vim.api.nvim_buf_is_valid(bufnr) then
132+
vim.api.nvim_buf_delete(bufnr, { force = true })
133+
end
122134
if opts.on_cancel then
123135
opts.on_cancel()
124136
end
@@ -356,8 +368,7 @@ function M.confirm(message, opts)
356368

357369
-- Enhanced window options with better styling
358370
win_opts.style = "minimal"
359-
win_opts.border = vim.o.winborder ~= "" and vim.o.winborder
360-
or { "", "", "", "", "", "", "", "" }
371+
win_opts.border = vim.o.winborder == "" and { "", "", "", "", "", "", "", "" } or nil
361372
win_opts.title_pos = "center"
362373
win_opts.title = {
363374
{ " MCPHUB Confirmation ", Text.highlights.header_btn },
@@ -388,9 +399,11 @@ function M.confirm(message, opts)
388399

389400
vim.schedule(function()
390401
if vim.api.nvim_win_is_valid(win) then
391-
if vim.api.nvim_win_is_valid(win) then
392-
vim.api.nvim_win_close(win, true)
393-
end
402+
vim.api.nvim_win_close(win, true)
403+
end
404+
405+
if vim.api.nvim_buf_is_valid(bufnr) then
406+
vim.api.nvim_buf_delete(bufnr, { force = true })
394407
end
395408
callback(confirmed, cancelled)
396409
end)
@@ -605,6 +618,13 @@ function M.open_auth_popup(server_name, auth_url)
605618
if vim.api.nvim_win_is_valid(input_win) then
606619
vim.api.nvim_win_close(input_win, true)
607620
end
621+
622+
if vim.api.nvim_buf_is_valid(info_buf) then
623+
vim.api.nvim_buf_delete(info_buf, { force = true })
624+
end
625+
if vim.api.nvim_buf_is_valid(input_buf) then
626+
vim.api.nvim_buf_delete(input_buf, { force = true })
627+
end
608628
-- Return focus to MCPHub window
609629
if State.ui_instance and State.ui_instance.window then
610630
vim.api.nvim_set_current_win(State.ui_instance.window)

0 commit comments

Comments
 (0)