Skip to content

Conversation

@olimorris
Copy link
Owner

@olimorris olimorris commented Feb 20, 2025

Description

This PR sets out to streamline the agents and tools implementation in the plugin, with a view to moving to native tool/function calling in the near future. Currently, all the logic sits within a tools/init.lua file. It's difficult to distinguish between function tools and command tools. And every time I have to get my head back into the code, I need to refresh myself on how I've built the solution.

This PR sets out a significant number of improvements.

Test Coverage

There is now significant test coverage for the feature. Thanks to mini.test's child processes capability, it's now possible to run tool tests from within a separate Neovim process. This saves me from having to mock Plenary.job and to test the feature in the way users do in the real world.

Queuing system (FIFO)

There were edge cases with the previous implementation whereby if a user ran a function tool, then a command tool, then another function tool, the two function tools would complete before the command tool. For some cases, this might not have been an issue, but in the example that I give in the README, i.e. asking the LLM to create Snake, this is a definite flaw. In fact, it turns out the only reason that video worked at all was because the human authorization delayed the function tools enough for the command tool to complete. But in this update, all of that goes away and the plugin will only execute the next tool if the previous one has completed.

Refactor

There's also been a significant refactor in the plugin as well. Instead of everything being in a tool/init file, it is now structured as follows:

strategies/chat/agents
├── executor/
│   ├── cmd.lua
│   ├── func.lua
│   ├── init.lua
│   ├── queue.lua
├── tools/
│   ├── cmd_runner.lua
│   ├── editor.lua
│   ├── files.lua
│   ├── rag.lua
├── init.lua

My hope is that it's much less daunting for users to make contributions to this particular feature in the plugin, and that it also provides a scalable base for the next phase of enhancements.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 20, 2025

Deploying codecompanion with  Cloudflare Pages  Cloudflare Pages

Latest commit: efbcdd1
Status: ✅  Deploy successful!
Preview URL: https://58121901.codecompanion.pages.dev
Branch Preview URL: https://refactor-tools.codecompanion.pages.dev

View logs

@olimorris olimorris merged commit acd48ef into main Mar 4, 2025
4 checks passed
@olimorris olimorris deleted the refactor/tools branch March 4, 2025 09:49
cleong14 pushed a commit to cleong14/codecompanion.nvim that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants