feat: remove unneeded debug command approach
This commit is contained in:
@@ -67,7 +67,6 @@ end
|
||||
-- PROMPT CONSTRUCTION
|
||||
------------------------------------------------------------------------------
|
||||
local function build_tools_available_block()
|
||||
-- We'll list each tool from tools_module.available_tools
|
||||
local lines = {}
|
||||
lines[#lines+1] = "<tools_available>"
|
||||
for _, t in ipairs(tools_module.available_tools) do
|
||||
@@ -94,7 +93,7 @@ local function build_prompt(user_input, dirs, conf)
|
||||
|
||||
-- 3) <task>
|
||||
local task_lines = {}
|
||||
table.insert(task_lines, "<task>")
|
||||
task_lines[#task_lines+1] = "<task>"
|
||||
task_lines[#task_lines+1] = user_input
|
||||
for _, file_path in ipairs(initial_files) do
|
||||
task_lines[#task_lines+1] = ("'%s' (see below for file content)"):format(file_path)
|
||||
@@ -154,7 +153,7 @@ local function handle_step_by_step_if_needed(prompt, conf)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- :ChatGPT Command
|
||||
-- :ChatGPT
|
||||
------------------------------------------------------------------------------
|
||||
local function run_chatgpt_command()
|
||||
local conf = config.load()
|
||||
@@ -221,7 +220,7 @@ local function run_chatgpt_command()
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- :ChatGPTPaste Command
|
||||
-- :ChatGPTPaste
|
||||
------------------------------------------------------------------------------
|
||||
local function run_chatgpt_paste_command()
|
||||
local conf = config.load()
|
||||
@@ -239,29 +238,21 @@ local function run_chatgpt_paste_command()
|
||||
return
|
||||
end
|
||||
|
||||
-- 1) Debug commands
|
||||
if data.commands and conf.enable_debug_commands then
|
||||
local results = {}
|
||||
for _, cmd in ipairs(data.commands) do
|
||||
table.insert(results, require('chatgpt_nvim').execute_debug_command(cmd, conf))
|
||||
end
|
||||
local output = table.concat(results, "\n\n")
|
||||
copy_to_clipboard(output)
|
||||
print("Debug command results copied to clipboard!")
|
||||
return
|
||||
end
|
||||
|
||||
-- 2) Tools (handle multiple calls in one request)
|
||||
-- Check if we have tools
|
||||
if data.tools then
|
||||
-- Must also verify project name
|
||||
if not data.project_name or data.project_name ~= conf.project_name then
|
||||
vim.api.nvim_err_writeln("Project name mismatch or missing. Aborting tool usage.")
|
||||
return
|
||||
end
|
||||
|
||||
local output_messages = tools_manager.handle_tool_calls(data.tools, conf, is_subpath, read_file)
|
||||
-- If the output is too large (over conf.prompt_char_limit?), we might respond with a special message.
|
||||
copy_to_clipboard(output_messages)
|
||||
print("Tool call results have been processed and copied to clipboard.")
|
||||
return
|
||||
end
|
||||
|
||||
-- 3) If we see project_name & files => final changes or file requests
|
||||
-- (If the user is still using older YAML style, we handle it, but not recommended.)
|
||||
-- If we see project_name & files => older YAML style. We handle it but it's discouraged now.
|
||||
if data.project_name and data.files then
|
||||
if data.project_name ~= conf.project_name then
|
||||
vim.api.nvim_err_writeln("Project name mismatch. Aborting.")
|
||||
@@ -294,7 +285,6 @@ local function run_chatgpt_paste_command()
|
||||
vim.api.nvim_err_writeln("Preview not closed in time. Aborting.")
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local final_files = data.files
|
||||
@@ -354,7 +344,7 @@ local function run_chatgpt_paste_command()
|
||||
"\n\nProject name: " .. (conf.project_name or ""),
|
||||
"\n\nBelow are the requested files from the project, each preceded by its filename in backticks and enclosed in triple backticks.\n",
|
||||
table.concat(file_sections, "\n"),
|
||||
"\n\nIf you need more files, please respond again in YAML listing additional files. Or use the new 'tools' array approach to read/edit files. If you have all info, provide final changes or just proceed."
|
||||
"\n\nIf you need more files, please respond again in YAML listing additional files, or use the 'tools:' approach. If you have all info, provide final changes or continue your instructions."
|
||||
}
|
||||
|
||||
local prompt = table.concat(sections, "\n")
|
||||
@@ -375,7 +365,7 @@ local function run_chatgpt_paste_command()
|
||||
print("Prompt (with requested files) copied to clipboard! Paste it into ChatGPT.")
|
||||
end
|
||||
else
|
||||
vim.api.nvim_err_writeln("Invalid response. Expected either 'tools' or 'project_name & files' in YAML.")
|
||||
vim.api.nvim_err_writeln("No tools or recognized file instructions found. Provide 'tools:' or older 'project_name & files'.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -425,94 +415,4 @@ M.run_chatgpt_command = run_chatgpt_command
|
||||
M.run_chatgpt_paste_command = run_chatgpt_paste_command
|
||||
M.run_chatgpt_current_buffer_command = run_chatgpt_current_buffer_command
|
||||
|
||||
-- Provide debug commands for "ls" and "grep"
|
||||
M.execute_debug_command = function(cmd, conf)
|
||||
if type(cmd) ~= "table" or not cmd.command then
|
||||
return "Invalid command object."
|
||||
end
|
||||
local command = cmd.command
|
||||
if command == "ls" then
|
||||
local dir = cmd.dir or "."
|
||||
local args = cmd.args or {}
|
||||
local cmd_str = "ls"
|
||||
if #args > 0 then
|
||||
cmd_str = cmd_str .. " " .. table.concat(args, " ")
|
||||
end
|
||||
cmd_str = cmd_str .. " " .. dir
|
||||
|
||||
local handle = io.popen(cmd_str)
|
||||
if not handle then
|
||||
return "Failed to run ls command."
|
||||
end
|
||||
local result = handle:read("*a") or ""
|
||||
handle:close()
|
||||
return "Listing files in: " .. dir .. "\n" .. result
|
||||
|
||||
elseif command == "grep" then
|
||||
local args = cmd.args or {}
|
||||
if #args == 0 then
|
||||
local pattern = cmd.pattern
|
||||
local target = cmd.target
|
||||
if not pattern or not target then
|
||||
return "Usage for grep: {command='grep', args=['-r','pattern','target']} or {pattern='<text>', target='<path>'}"
|
||||
end
|
||||
local stat = vim.loop.fs_stat(target)
|
||||
if not stat then
|
||||
return "Cannot grep: target path does not exist"
|
||||
end
|
||||
|
||||
local function do_grep(search_string, filepath)
|
||||
local c = read_file(filepath)
|
||||
if not c then
|
||||
return "Could not read file: " .. filepath
|
||||
end
|
||||
local lines = {}
|
||||
local line_num = 0
|
||||
for line in c:gmatch("([^\n]*)\n?") do
|
||||
line_num = line_num + 1
|
||||
if line:find(search_string, 1, true) then
|
||||
lines[#lines+1] = filepath .. ":" .. line_num .. ":" .. line
|
||||
end
|
||||
end
|
||||
return (#lines == 0) and ("No matches in " .. filepath) or table.concat(lines, "\n")
|
||||
end
|
||||
|
||||
if stat.type == "directory" then
|
||||
local h = io.popen("ls -p " .. target .. " | grep -v /")
|
||||
if not h then
|
||||
return "Failed to read directory contents for grep."
|
||||
end
|
||||
local all_files = {}
|
||||
for file in h:read("*a"):gmatch("[^\n]+") do
|
||||
all_files[#all_files+1] = target .. "/" .. file
|
||||
end
|
||||
h:close()
|
||||
local results = {}
|
||||
for _, f in ipairs(all_files) do
|
||||
local fstat = vim.loop.fs_stat(f)
|
||||
if fstat and fstat.type == "file" then
|
||||
results[#results+1] = do_grep(pattern, f)
|
||||
end
|
||||
end
|
||||
return table.concat(results, "\n")
|
||||
else
|
||||
return do_grep(pattern, target)
|
||||
end
|
||||
|
||||
else
|
||||
-- new approach with flags/args
|
||||
local cmd_str = "grep " .. table.concat(args, " ")
|
||||
local handle = io.popen(cmd_str)
|
||||
if not handle then
|
||||
return "Failed to run grep command."
|
||||
end
|
||||
local result = handle:read("*a") or ""
|
||||
handle:close()
|
||||
return result
|
||||
end
|
||||
else
|
||||
return "Unknown command: " .. command
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user