fix: execute command tool, improving prompts
This commit is contained in:
@@ -2,8 +2,6 @@ project_name: "chatgpt.vim"
|
||||
default_prompt_blocks:
|
||||
- "basic-prompt"
|
||||
- "secure-coding"
|
||||
initial_files:
|
||||
- "README.md"
|
||||
|
||||
debug: false
|
||||
improved_debug: false
|
||||
|
||||
@@ -342,7 +342,7 @@ local M = {
|
||||
- Always start with 1 or 2, but afterwards you can mix 1, 2, 3, and 4 as needed.
|
||||
- Include `project_name: "my_project"` whenever you call `tools`.
|
||||
- Keep each tool call in the `tools` array (multiple if needed).
|
||||
- **Never write to a file you haven’t read** in this session (unless creating a new file).
|
||||
- **Never write to a file you haven’t read** in this session and already got the content from an response (unless creating a new file).
|
||||
- Follow secure coding guidelines (input validation, least privilege, no sensitive info in logs, etc.).
|
||||
- When done, provide a final answer **without** calling any tools.
|
||||
]],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,7 +25,7 @@ M.available_tools = {
|
||||
{
|
||||
name = "executeCommand",
|
||||
usage = "Run a shell command. Provide { tool='executeCommand', command='...' }",
|
||||
explanation = "Use with caution, especially for destructive operations (rm, sudo, etc.)."
|
||||
explanation = "Just run one single command per tool invocation, without comment. It must be a single line. Use with caution, especially for destructive operations (rm, sudo, etc.)."
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user