37 lines
992 B
Lua
37 lines
992 B
Lua
local M = {}
|
|
|
|
M.run = function(tool_call, conf, prompt_user_tool_accept, is_subpath, read_file)
|
|
-- Validate the command exists
|
|
local cmd = tool_call.command
|
|
if not cmd then
|
|
return "[executeCommand] Missing 'command'."
|
|
end
|
|
|
|
-- Capture stderr and stdout together by redirecting stderr to stdout
|
|
-- This will help diagnose if there's an error causing no output
|
|
cmd = cmd .. " 2>&1"
|
|
|
|
-- Attempt to popen the command
|
|
local handle = io.popen(cmd, "r")
|
|
if not handle then
|
|
return string.format("Tool [executeCommand '%s'] FAILED to popen.", cmd)
|
|
end
|
|
|
|
-- Read the full output (stdout + stderr)
|
|
local result = handle:read("*a") or ""
|
|
|
|
-- Attempt to close, capturing exit info
|
|
local _, exit_reason, exit_code = handle:close()
|
|
|
|
-- Provide a richer summary including exit code and reason
|
|
return string.format(
|
|
"Tool [executeCommand '%s'] exited with code %s (%s)\n%s",
|
|
cmd,
|
|
tostring(exit_code),
|
|
tostring(exit_reason),
|
|
result
|
|
)
|
|
end
|
|
|
|
return M
|