Skip to content

Commit

Permalink
add code_runner tool
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed May 5, 2024
1 parent f45bd79 commit 0a5f27f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lua/codecompanion/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,19 @@ This may be useful for testing code you've written or for doing mathematical cal
The tools available to you, and their config:
- `python_code_executor` - This tool allows you to execute Python code on my machine. The code must be placed within the parameters tag. For example:
- `code_runner` - This tool allows you to execute code on my machine. The code and language must be specified as inputs. For example:
```xml
<tool>
<name>python_code_executor</name>
<name>code_runner</name>
<parameters>
<inputs>
<!-- Choose the language to run -->
<!-- Currently you can only choose python or ruby -->
<lang>python</lang>
<!-- Anything within the code tag will be executed -->
<code>print("Hello World")</code>
<!-- The version of Python to use -->
<!-- The version of the lang to use -->
<version>3.11.0</version>
</inputs>
</parameters>
Expand Down
5 changes: 5 additions & 0 deletions lua/codecompanion/tools/code_runner.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local M = {}

function M.run(bufnr, xml) end

return M
13 changes: 11 additions & 2 deletions lua/codecompanion/tools/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local handler = require("codecompanion.utils.xml.xmlhandler.tree")
local log = require("codecompanion.utils.log")
local xml2lua = require("codecompanion.utils.xml.xml2lua")

local M = {}
Expand All @@ -7,9 +8,17 @@ function M.run(bufnr, tools)
local parser = xml2lua.parser(handler)
parser:parse(tools)

for i, p in pairs(handler.root.tool) do
print(i, p)
log:debug("Parsed xml: %s", handler.root)

local xml = handler.root.tool

local ok, tool = pcall(require, "codecompanion.tools." .. xml.name)
if not ok then
log:error("Tool not found: %s", xml.name)
return
end

tool.run(bufnr, xml)
end

return M

0 comments on commit 0a5f27f

Please sign in to comment.