diff --git a/lua/shelbybark/plugins/codecompanion.lua b/lua/shelbybark/plugins/codecompanion.lua index 20c1701..daa1548 100644 --- a/lua/shelbybark/plugins/codecompanion.lua +++ b/lua/shelbybark/plugins/codecompanion.lua @@ -9,10 +9,6 @@ return { "j-hui/fidget.nvim", -- For statusline integration -- "nvim-lualine/lualine.nvim", - { - "franco-ruggeri/codecompanion-lualine.nvim", -- Add this line - dependencies = { "olimorris/codecompanion.nvim" }, - }, }, event = "VeryLazy", -- Lazy load the plugin config = function() @@ -52,6 +48,18 @@ return { }, }) end, + anthropic_haiku = function() + return require("codecompanion.adapters").extend("anthropic", { + env = { + api_key = "ANTHROPIC_API_KEY", + }, + schema = { + model = { + default = "claude-haiku-4-5-20251001", + }, + }, + }) + end, }, }, -- Display settings for the chat window @@ -74,15 +82,15 @@ return { -- Optional: Set up keymaps vim.api.nvim_set_keymap( "n", - "cc", - "CodeCompanionChat Toggle", - { noremap = true, silent = true } + "cc", + "CodeCompanionChat anthropic_haiku Toggle", + { noremap = true, silent = true, desc = "Chat with Claude Haiku" } ) vim.api.nvim_set_keymap( "v", - "cc", - "CodeCompanionChat Toggle", - { noremap = true, silent = true } + "cc", + "CodeCompanionChat anthropic_haiku Toggle", + { noremap = true, silent = true, desc = "Chat with Claude Haiku" } ) vim.api.nvim_set_keymap("n", "ca", "CodeCompanionActions", { noremap = true, silent = true }) vim.api.nvim_set_keymap("v", "ca", "CodeCompanionActions", { noremap = true, silent = true }) @@ -110,6 +118,8 @@ return { model_info = "Claude Sonnet (claude-sonnet-4-20250514)" elseif current_adapter == "anthropic_opus" then model_info = "Claude Opus (claude-opus-4-5-20251101)" + elseif current_adapter == "anthropic_haiku" then + model_info = "Claude Haiku (claude-haiku-4-5-20251001)" end vim.notify(string.format("Current CodeCompanion model: %s", model_info), vim.log.levels.INFO) @@ -120,18 +130,19 @@ return { vim.api.nvim_create_user_command("CodeCompanionSwitchModel", function(args) local model = args.args if model == "" then - vim.notify("Available models: sonnet, opus", vim.log.levels.INFO) + vim.notify("Available models: sonnet, opus, haiku", vim.log.levels.INFO) return end local adapter_map = { sonnet = "anthropic", opus = "anthropic_opus", + haiku = "anthropic_haiku", } local adapter = adapter_map[model:lower()] if not adapter then - vim.notify("Invalid model. Use: sonnet, opus", vim.log.levels.ERROR) + vim.notify("Invalid model. Use: sonnet, opus, haiku", vim.log.levels.ERROR) return end @@ -146,11 +157,25 @@ return { end, { nargs = 1, complete = function() - return { "sonnet", "opus" } + return { "sonnet", "opus", "haiku" } end, - desc = "Switch CodeCompanion model (sonnet/opus)", + desc = "Switch CodeCompanion model (sonnet/opus/haiku)", }) + -- Additional keymaps for Sonnet (backup primary) + vim.api.nvim_set_keymap( + "n", + "cs", + "CodeCompanionChat anthropic Toggle", + { noremap = true, silent = true, desc = "Chat with Claude Sonnet" } + ) + vim.api.nvim_set_keymap( + "v", + "cs", + "CodeCompanionChat anthropic Toggle", + { noremap = true, silent = true, desc = "Chat with Claude Sonnet" } + ) + -- Additional keymaps for Opus vim.api.nvim_set_keymap( "n", @@ -164,5 +189,19 @@ return { "CodeCompanionChat anthropic_opus Toggle", { noremap = true, silent = true, desc = "Chat with Claude Opus" } ) + + -- Additional keymaps for Haiku + vim.api.nvim_set_keymap( + "n", + "ch", + "CodeCompanionChat anthropic_haiku Toggle", + { noremap = true, silent = true, desc = "Chat with Claude Haiku" } + ) + vim.api.nvim_set_keymap( + "v", + "ch", + "CodeCompanionChat anthropic_haiku Toggle", + { noremap = true, silent = true, desc = "Chat with Claude Haiku" } + ) end, } diff --git a/lua/shelbybark/plugins/lualine.lua b/lua/shelbybark/plugins/lualine.lua index 9bff813..9259385 100644 --- a/lua/shelbybark/plugins/lualine.lua +++ b/lua/shelbybark/plugins/lualine.lua @@ -67,74 +67,79 @@ return { } -- Enhanced CodeCompanion status function with model display - -- local function codecompanion_status() - -- local ok, codecompanion = pcall(require, "codecompanion") - -- if not ok then - -- return "" - -- end - -- - -- -- Get current adapter and model info - -- local current_adapter = nil - -- local current_model = nil - -- - -- -- Try to get adapter from active chat buffer - -- local chat_ok, chat = pcall(codecompanion.buf_get_chat) - -- if chat_ok and chat and chat.adapter then - -- current_adapter = chat.adapter.name or chat.adapter - -- current_model = chat.adapter.schema and chat.adapter.schema.model and chat.adapter.schema.model.default - -- end - -- - -- -- If no active chat, get default adapter from config - -- if not current_adapter then - -- local config_ok, config = pcall(function() - -- return codecompanion.config.strategies.chat.adapter - -- end) - -- if config_ok and config then - -- current_adapter = config - -- -- Try to get model from adapter config - -- local adapter_config_ok, adapter_config = pcall(function() - -- return codecompanion.config.adapters.http[config] - -- end) - -- if adapter_config_ok and type(adapter_config) == "function" then - -- local adapter_instance_ok, adapter_instance = pcall(adapter_config) - -- if adapter_instance_ok and adapter_instance.schema and adapter_instance.schema.model then - -- current_model = adapter_instance.schema.model.default - -- end - -- end - -- end - -- end - -- - -- -- Format the display string - -- local status_parts = {} - -- - -- -- Check for active requests/chats first - -- local status = codecompanion.status() - -- if status and status ~= "" then - -- table.insert(status_parts, "🤖") - -- elseif chat_ok and chat then - -- table.insert(status_parts, "💬") - -- end - -- - -- -- Add model info - -- if current_model then - -- -- Shorten model names for better display - -- local short_model = current_model - -- :gsub("claude%-sonnet%-4%-20250514", "Sonnet") - -- :gsub("claude%-opus%-4%-5%-20251101", "Opus") - -- :gsub("claude%-3%-5%-sonnet%-20241022", "3.5S") - -- :gsub("claude%-3%-haiku%-20240307", "Haiku") - -- :gsub("gpt%-4o", "GPT-4o") - -- :gsub("gpt%-4", "GPT-4") - -- :gsub("gpt%-3.5%-turbo", "GPT-3.5") - -- table.insert(status_parts, short_model) - -- elseif current_adapter then - -- -- Show adapter name if model not available - -- local short_adapter = current_adapter:gsub("anthropic", "Claude"):gsub("openai", "OpenAI") - -- table.insert(status_parts, short_adapter) - -- end - -- - -- return table.concat(status_parts, " ") - -- end + local function codecompanion_status() + local ok, codecompanion = pcall(require, "codecompanion") + if not ok then + return "" + end + + -- Always start with CodeCompanion indicator since it's loaded + local status_parts = { "🤖" } + + -- Try to get current adapter and model info + local current_adapter = nil + local current_model = nil + + -- First try to get from active chat + local chat_ok, chat = pcall(codecompanion.last_chat) + if chat_ok and chat and chat.adapter then + current_adapter = chat.adapter.name or "active" + if chat.adapter.schema and chat.adapter.schema.model then + current_model = chat.adapter.schema.model.default or chat.adapter.schema.model + end + end + + -- If no active chat, get from config + if not current_adapter and codecompanion.config then + if + codecompanion.config.strategies + and codecompanion.config.strategies.chat + and codecompanion.config.strategies.chat.adapter + then + current_adapter = codecompanion.config.strategies.chat.adapter + + -- Try to get model from adapter config + if + codecompanion.config.adapters + and codecompanion.config.adapters.http + and codecompanion.config.adapters.http[current_adapter] + and type(codecompanion.config.adapters.http[current_adapter]) == "function" + then + local success, adapter_instance = pcall(codecompanion.config.adapters.http[current_adapter]) + if + success + and adapter_instance + and adapter_instance.schema + and adapter_instance.schema.model + and adapter_instance.schema.model.default + then + current_model = adapter_instance.schema.model.default + end + end + end + end + + -- Add model/adapter info + if current_model then + -- Shorten model names for better display + local short_model = current_model + :gsub("claude%-sonnet%-4%-20250514", "Sonnet") + :gsub("claude%-opus%-4%-5%-20251101", "Opus") + :gsub("claude%-3%-5%-sonnet%-20241022", "3.5S") + :gsub("claude%-3%-haiku%-20240307", "Haiku") + :gsub("gpt%-4o", "GPT-4o") + :gsub("gpt%-4", "GPT-4") + :gsub("gpt%-3.5%-turbo", "GPT-3.5") + table.insert(status_parts, short_model) + elseif current_adapter then + -- Show adapter name if model not available + local short_adapter = current_adapter:gsub("anthropic", "Claude"):gsub("openai", "OpenAI") + table.insert(status_parts, short_adapter) + end + + -- Return the formatted string + return table.concat(status_parts, " ") + end local colors = { blue = "#65D1FF", @@ -204,8 +209,8 @@ return { }, lualine_x = { { - "codecompanion", - -- codecompanion_status, + -- "codecompanion", + codecompanion_status, color = { fg = colors.green }, }, {