fix: execute command tool, improving prompts
This commit is contained in:
@@ -1,17 +1,36 @@
|
||||
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
|
||||
local handle = io.popen(cmd)
|
||||
|
||||
-- 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 ""
|
||||
handle:close()
|
||||
return string.format("Tool [executeCommand '%s'] Result:\n%s", cmd, result)
|
||||
|
||||
-- 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
|
||||
|
||||
Reference in New Issue
Block a user