diff --git a/chatgpt_config.yaml b/chatgpt_config.yaml index 8d36183..2d2a0a8 100644 --- a/chatgpt_config.yaml +++ b/chatgpt_config.yaml @@ -2,8 +2,6 @@ project_name: "chatgpt.vim" default_prompt_blocks: - "basic-prompt" - "secure-coding" -initial_files: - - "README.md" debug: false improved_debug: false diff --git a/lua/chatgpt_nvim/prompts.lua b/lua/chatgpt_nvim/prompts.lua index 3b6ad1d..1739e3b 100644 --- a/lua/chatgpt_nvim/prompts.lua +++ b/lua/chatgpt_nvim/prompts.lua @@ -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. ]], diff --git a/lua/chatgpt_nvim/tools/execute_command.lua b/lua/chatgpt_nvim/tools/execute_command.lua index 5fb9274..ee4ccbb 100644 --- a/lua/chatgpt_nvim/tools/execute_command.lua +++ b/lua/chatgpt_nvim/tools/execute_command.lua @@ -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 diff --git a/lua/chatgpt_nvim/tools/init.lua b/lua/chatgpt_nvim/tools/init.lua index 3808175..9571c6c 100644 --- a/lua/chatgpt_nvim/tools/init.lua +++ b/lua/chatgpt_nvim/tools/init.lua @@ -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.)." }, }