From 830ed444f920bd9380736b4081afc5357018046a Mon Sep 17 00:00:00 2001 From: hezirel <80560775+hezirel@users.noreply.github.com> Date: Tue, 13 May 2025 19:44:09 +0200 Subject: [PATCH 1/2] feat(header): slim header --- lua/gp/init.lua | 74 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index 128914c..d754ce8 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -7,23 +7,23 @@ local config = require("gp.config") local M = { - _Name = "Gp", -- plugin name - _state = {}, -- table of state variables - agents = {}, -- table of agents - cmd = {}, -- default command functions - config = {}, -- config variables - hooks = {}, -- user defined command functions - defaults = require("gp.defaults"), -- some useful defaults + _Name = "Gp", -- plugin name + _state = {}, -- table of state variables + agents = {}, -- table of agents + cmd = {}, -- default command functions + config = {}, -- config variables + hooks = {}, -- user defined command functions + defaults = require("gp.defaults"), -- some useful defaults deprecator = require("gp.deprecator"), -- handle deprecated options dispatcher = require("gp.dispatcher"), -- handle communication with LLM providers - helpers = require("gp.helper"), -- helper functions - imager = require("gp.imager"), -- image generation module - logger = require("gp.logger"), -- logger module - render = require("gp.render"), -- render module - spinner = require("gp.spinner"), -- spinner module - tasker = require("gp.tasker"), -- tasker module - vault = require("gp.vault"), -- handles secrets - whisper = require("gp.whisper"), -- whisper module + helpers = require("gp.helper"), -- helper functions + imager = require("gp.imager"), -- image generation module + logger = require("gp.logger"), -- logger module + render = require("gp.render"), -- render module + spinner = require("gp.spinner"), -- spinner module + tasker = require("gp.tasker"), -- tasker module + vault = require("gp.vault"), -- handles secrets + whisper = require("gp.whisper"), -- whisper module } -------------------------------------------------------------------------------- @@ -137,11 +137,11 @@ M.setup = function(opts) elseif not agent.model or not agent.system_prompt then M.logger.warning( "Agent " - .. name - .. " is missing model or system_prompt\n" - .. "If you want to disable an agent, use: { name = '" - .. name - .. "', disable = true }," + .. name + .. " is missing model or system_prompt\n" + .. "If you want to disable an agent, use: { name = '" + .. name + .. "', disable = true }," ) M.agents[name] = nil end @@ -282,9 +282,9 @@ end M.Target = { rewrite = 0, -- for replacing the selection, range or the current line - append = 1, -- for appending after the selection, range or the current line + append = 1, -- for appending after the selection, range or the current line prepend = 2, -- for prepending before the selection, range or the current line - popup = 3, -- for writing into the popup window + popup = 3, -- for writing into the popup window -- for writing into a new buffer ---@param filetype nil | string # nil = same as the original buffer @@ -378,8 +378,8 @@ M._toggle = {} M._toggle_kind = { unknown = 0, -- unknown toggle - chat = 1, -- chat toggle - popup = 2, -- popup toggle + chat = 1, -- chat toggle + popup = 2, -- popup toggle context = 3, -- context toggle } @@ -387,13 +387,13 @@ M._toggle_kind = { ---@return boolean # true if toggle was closed M._toggle_close = function(kind) if - M._toggle[kind] - and M._toggle[kind].win - and M._toggle[kind].buf - and M._toggle[kind].close - and vim.api.nvim_win_is_valid(M._toggle[kind].win) - and vim.api.nvim_buf_is_valid(M._toggle[kind].buf) - and vim.api.nvim_win_get_buf(M._toggle[kind].win) == M._toggle[kind].buf + M._toggle[kind] + and M._toggle[kind].win + and M._toggle[kind].buf + and M._toggle[kind].close + and vim.api.nvim_win_is_valid(M._toggle[kind].win) + and vim.api.nvim_buf_is_valid(M._toggle[kind].buf) + and vim.api.nvim_win_get_buf(M._toggle[kind].win) == M._toggle[kind].buf then if #vim.api.nvim_list_wins() == 1 then M.logger.warning("Can't close the last window.") @@ -473,7 +473,7 @@ M.not_chat = function(buf, file_name) end end if not header_found then - return "missing file header" + return nil end return nil @@ -609,10 +609,10 @@ end M.BufTarget = { current = 0, -- current window - popup = 1, -- popup window - split = 2, -- split window - vsplit = 3, -- vsplit window - tabnew = 4, -- new tab + popup = 1, -- popup window + split = 2, -- split window + vsplit = 3, -- vsplit window + tabnew = 4, -- new tab } ---@param params table | string # table with args or string args @@ -1233,7 +1233,7 @@ M.cmd.ChatFinder = function() local command_buf, command_win, command_close, command_resize = M.render.popup( nil, "Search: /|navigate |picker |exit " - .. "/////t|open/float/split/vsplit/tab/toggle", + .. "/////t|open/float/split/vsplit/tab/toggle", function(w, h) return w - left - right, 1, h - bottom, left end, From 7938871d023864db1d74bf6611c94ecf0a9db82c Mon Sep 17 00:00:00 2001 From: hezirel <80560775+hezirel@users.noreply.github.com> Date: Sat, 17 May 2025 17:23:53 +0200 Subject: [PATCH 2/2] feat(header): add option to get slim header without filename --- lua/gp/config.lua | 25 +++++++++++++------------ lua/gp/init.lua | 6 +++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lua/gp/config.lua b/lua/gp/config.lua index 1924e43..5ea6233 100644 --- a/lua/gp/config.lua +++ b/lua/gp/config.lua @@ -315,11 +315,12 @@ local config = { chat_assistant_prefix = { "🤖:", "[{{agent}}]" }, -- The banner shown at the top of each chat file. chat_template = require("gp.defaults").chat_template, + slim_template_header = true, -- if you want more real estate in your chat files and don't need the helper text -- chat_template = require("gp.defaults").short_chat_template, -- chat topic generation prompt chat_topic_gen_prompt = "Summarize the topic of our conversation above" - .. " in two or three words. Respond only with those words.", + .. " in two or three words. Respond only with those words.", -- chat topic model (string with model name or table with model name and parameters) -- explicitly confirm deletion of a chat file chat_confirm_delete = true, @@ -378,16 +379,16 @@ local config = { -- templates template_selection = "I have the following from {{filename}}:" - .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}", + .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}", template_rewrite = "I have the following from {{filename}}:" - .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" - .. "\n\nRespond exclusively with the snippet that should replace the selection above.", + .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" + .. "\n\nRespond exclusively with the snippet that should replace the selection above.", template_append = "I have the following from {{filename}}:" - .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" - .. "\n\nRespond exclusively with the snippet that should be appended after the selection above.", + .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" + .. "\n\nRespond exclusively with the snippet that should be appended after the selection above.", template_prepend = "I have the following from {{filename}}:" - .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" - .. "\n\nRespond exclusively with the snippet that should be prepended before the selection above.", + .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" + .. "\n\nRespond exclusively with the snippet that should be prepended before the selection above.", template_command = "{{command}}", -- https://platform.openai.com/docs/guides/speech-to-text/quickstart @@ -569,9 +570,9 @@ local config = { -- GpImplement rewrites the provided selection/range based on comments in it Implement = function(gp, params) local template = "Having following from {{filename}}:\n\n" - .. "```{{filetype}}\n{{selection}}\n```\n\n" - .. "Please rewrite this according to the contained instructions." - .. "\n\nRespond exclusively with the snippet that should replace the selection above." + .. "```{{filetype}}\n{{selection}}\n```\n\n" + .. "Please rewrite this according to the contained instructions." + .. "\n\nRespond exclusively with the snippet that should replace the selection above." local agent = gp.get_command_agent() gp.logger.info("Implementing selection with agent: " .. agent.name) @@ -582,7 +583,7 @@ local config = { agent, template, nil, -- command will run directly without any prompting for user input - nil -- no predefined instructions (e.g. speech-to-text from Whisper) + nil -- no predefined instructions (e.g. speech-to-text from Whisper) ) end, diff --git a/lua/gp/init.lua b/lua/gp/init.lua index d754ce8..45071a5 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -473,7 +473,11 @@ M.not_chat = function(buf, file_name) end end if not header_found then - return nil + if M.config.slim_template_header then + return nil + else + return "missing file header" + end end return nil