Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: tool_schema.output.rejected getting function as action #1081

Closed
5 tasks done
ravitemer opened this issue Mar 6, 2025 · 3 comments
Closed
5 tasks done

[Bug]: tool_schema.output.rejected getting function as action #1081

ravitemer opened this issue Mar 6, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@ravitemer
Copy link
Contributor

Did you check the docs and existing issues?

  • I have read all the docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched for existing issues/discussions
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.10

Operating system/version

ubuntu 22

Describe the bug

ravitemer/mcphub.nvim#10

Error occurs when rejecting a tool call with builtin @files tool as well.

Error executing vim.schedule lua callback: ...lazy/mcphub.nvim/lua/mcphub/extensions/codecompanion.lua:155: attempt to index local 'action' (a function value)
stack traceback:
	...lazy/mcphub.nvim/lua/mcphub/extensions/codecompanion.lua:155: in function 'rejected'
	...a/codecompanion/strategies/chat/agents/executor/init.lua:59: in function 'rejected'
	...a/codecompanion/strategies/chat/agents/executor/init.lua:127: in function 'f'

Steps To Reproduce

Use builtin @files tool and reject.

Expected Behavior

action should be a table

init.lua file

--[[
NOTE: Set the config path to enable the copilot adapter to work.
It will search the following paths for a token:
  - "$CODECOMPANION_TOKEN_PATH/github-copilot/hosts.json"
  - "$CODECOMPANION_TOKEN_PATH/github-copilot/apps.json"
--]]
vim.env["CODECOMPANION_TOKEN_PATH"] = vim.fn.expand("~/.config")

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

-- Your CodeCompanion setup
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
      { "nvim-lua/plenary.nvim" },
      -- Test with blink.cmp (delete if not required)
      {
        "saghen/blink.cmp",
        lazy = false,
        version = "*",
        opts = {
          keymap = {
            preset = "enter",
            ["<S-Tab>"] = { "select_prev", "fallback" },
            ["<Tab>"] = { "select_next", "fallback" },
          },
          cmdline = { sources = { "cmdline" } },
          sources = {
            default = { "lsp", "path", "buffer", "codecompanion" },
          },
        },
      },
      -- Test with nvim-cmp
      -- { "hrsh7th/nvim-cmp" },
    },
    opts = {
      --Refer to: https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua
      strategies = {
        --NOTE: Change the adapter as required
        chat = { adapter = "copilot" },
        inline = { adapter = "copilot" },
      },
      opts = {
        log_level = "DEBUG",
      },
    },
  },
}

-- Leaving this comment in to see if the issue author notices ;-)
-- This is so I can tell if they've really tested with their own repro.lua file

require("lazy.minit").repro({ spec = plugins })

-- Setup Tree-sitter
local ts_status, treesitter = pcall(require, "nvim-treesitter.configs")
if ts_status then
  treesitter.setup({
    ensure_installed = { "lua", "markdown", "markdown_inline", "yaml", "diff" },
    highlight = { enable = true },
  })
end

-- Setup nvim-cmp
-- local cmp_status, cmp = pcall(require, "cmp")
-- if cmp_status then
--   cmp.setup({
--     mapping = cmp.mapping.preset.insert({
--       ["<C-b>"] = cmp.mapping.scroll_docs(-4),
--       ["<C-f>"] = cmp.mapping.scroll_docs(4),
--       ["<C-Space>"] = cmp.mapping.complete(),
--       ["<C-e>"] = cmp.mapping.abort(),
--       ["<CR>"] = cmp.mapping.confirm({ select = true }),
--       -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
--     }),
--   })
-- end

Log output

Error executing vim.schedule lua callback: ...lazy/mcphub.nvim/lua/mcphub/extensions/codecompanion.lua:155: attempt to index local 'action' (a function value)
stack traceback:
...lazy/mcphub.nvim/lua/mcphub/extensions/codecompanion.lua:155: in function 'rejected'
...a/codecompanion/strategies/chat/agents/executor/init.lua:59: in function 'rejected'
...a/codecompanion/strategies/chat/agents/executor/init.lua:127: in function 'f'

Have you provided and tested with a repro.lua file?

  • Yes, I have tested and provided a repro.lua file
@ravitemer ravitemer added the bug Something isn't working label Mar 6, 2025
Copy link
Contributor

github-actions bot commented Mar 6, 2025

Important

If your issue does NOT contain a valid minimal.lua then this issue may be closed without a response.
Thanks for respecting my time and efforts.

Thanks @ravitemer. I'll get to this as soon as I can.

In the meantime, please ensure:

  • This is a plugin related issue and not an issue with your configuration
  • You've searched for similar issues (try the discussions too)
  • You've checked out the documentation
  • The tables in your configuration are nested correctly (again, check out the documentation)
  • The issue title is accurate
  • There is a valid minimal.lua file included so I can try and recreate the issue

@ravitemer
Copy link
Contributor Author

ravitemer commented Mar 6, 2025

---Setup the tool to be executed
---@param input? any
---@return nil
function Executor:setup(input)
  if self.queue:is_empty() then
    finalize_agent(self)
    return log:debug("Executor:execute - Queue empty")
  end
  if self.agent.status == self.agent.constants.STATUS_ERROR then
    finalize_agent(self)
    return log:debug("Executor:execute - Error")
  end

  -- Get the next tool to run
  self.tool = self.queue:pop()

  -- Setup the handlers
  self:setup_handlers()
  self.handlers.setup() -- Call this early as cmd_runner needs to setup its cmds dynamically

  -- Get the first command to run
  local cmd = self.tool.cmds[1]
  log:debug("Executor:execute - `%s` tool", self.tool.name)

  -- Check if the tool requires approval
  if self.tool.opts and self.tool.opts.requires_approval and not vim.g.codecompanion_auto_tool_mode then
    log:debug("Executor:execute - Asking for approval")

    local prompt = self.output.prompt(self.tool)
    if prompt == nil or prompt == "" then
      prompt = ("Run the %q tool?"):format(self.tool.name)
    end

    local ok, choice = pcall(vim.fn.confirm, prompt, "&Yes\n&No\n&Cancel")
    if not ok or choice == 0 or choice == 3 then -- Esc or Cancel
      log:debug("Executor:execute - Tool cancelled")
      finalize_agent(self)
      return self:close()
    end
    if choice == 1 then -- Yes
      log:debug("Executor:execute - Tool approved")
      self:execute(cmd, input)
    end
    if choice == 2 then -- No
      log:debug("Executor:execute - Tool rejected")
      self.output.rejected(cmd)
      return self:setup()
    end
  else
    self:execute(cmd, input)
  end
end

the cmd is being set to the actual function here when passed to self.output.rejected(cmd)

@olimorris
Copy link
Owner

Thanks for catching this @ravitemer. Fixed this in the latest patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants