diff --git a/docs/codecompanion_model_status.md b/docs/codecompanion_model_status.md new file mode 100644 index 0000000..5c42aaa --- /dev/null +++ b/docs/codecompanion_model_status.md @@ -0,0 +1,57 @@ +# CodeCompanion Model Status Display + +This document explains the enhancements made to display the current CodeCompanion model in your Neovim status bar. + +## Features Added + +### 1. Enhanced Status Bar Display +The lualine configuration now includes an improved `codecompanion_status()` function that shows: +- Activity indicators (🤖 for active requests, 💬 for active chats) +- Current model being used with shortened names for better display: + - `claude-sonnet-4-20250514` → `Sonnet` + - `claude-opus-4-5-20251101` → `Opus` + - `claude-3-5-sonnet-20241022` → `3.5S` + - `claude-3-haiku-20240307` → `Haiku` + - `gpt-4o` → `GPT-4o` + - `gpt-4` → `GPT-4` + - `gpt-3.5-turbo` → `GPT-3.5` + +### 2. New Commands +- `:CodeCompanionModel` - Shows the current model being used +- `:CodeCompanionSwitchModel [sonnet|opus]` - Switch between available models + +### 3. New Keymaps +- `cm` - Show current CodeCompanion model +- `cc` - Toggle CodeCompanion chat (existing) +- `ca` - CodeCompanion actions (existing) +- `co` - Chat with Claude Opus specifically (existing) + +## How It Works + +The status function tries multiple approaches to determine the current model: +1. First, it checks if there's an active chat buffer and gets the adapter/model from it +2. If no active chat, it falls back to the default adapter from the configuration +3. It then tries to resolve the actual model name from the adapter configuration +4. Finally, it formats the display with activity indicators and shortened model names + +## Usage Examples + +```vim +" Show current model +:CodeCompanionModel + +" Switch to Sonnet model +:CodeCompanionSwitchModel sonnet + +" Switch to Opus model +:CodeCompanionSwitchModel opus + +" Show current model (keymap) +cm +``` + +## Configuration + +The status bar component is automatically integrated into your lualine configuration in the `lualine_x` section, positioned between other status indicators and file type information. + +The model names are shortened to save space in the status bar while still being recognizable. You can modify the name mappings in the `codecompanion_status()` function if you prefer different abbreviations. \ No newline at end of file diff --git a/lua/shelbybark/plugins/codecompanion.lua b/lua/shelbybark/plugins/codecompanion.lua index 0954c7f..10332fc 100644 --- a/lua/shelbybark/plugins/codecompanion.lua +++ b/lua/shelbybark/plugins/codecompanion.lua @@ -83,6 +83,71 @@ return { vim.api.nvim_set_keymap("n", "ca", "CodeCompanionActions", { noremap = true, silent = true }) vim.api.nvim_set_keymap("v", "ca", "CodeCompanionActions", { noremap = true, silent = true }) + vim.api.nvim_set_keymap( + "n", + "cm", + "CodeCompanionModel", + { noremap = true, silent = true, desc = "Show current CodeCompanion model" } + ) + + + -- Create commands to show and change current model + vim.api.nvim_create_user_command("CodeCompanionModel", function() + local ok, codecompanion = pcall(require, "codecompanion") + if not ok then + vim.notify("CodeCompanion not available", vim.log.levels.ERROR) + return + end + + -- Get current adapter info + local current_adapter = codecompanion.config.strategies.chat.adapter + local model_info = "Unknown" + + if current_adapter == "anthropic" then + model_info = "Claude Sonnet (claude-sonnet-4-20250514)" + elseif current_adapter == "anthropic_opus" then + model_info = "Claude Opus (claude-opus-4-5-20251101)" + end + + vim.notify(string.format("Current CodeCompanion model: %s", model_info), vim.log.levels.INFO) + end, { + desc = "Show current CodeCompanion model" + }) + + 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) + return + end + + local adapter_map = { + sonnet = "anthropic", + opus = "anthropic_opus" + } + + local adapter = adapter_map[model:lower()] + if not adapter then + vim.notify("Invalid model. Use: sonnet, opus", vim.log.levels.ERROR) + return + end + + -- Update the config + require("codecompanion").config.strategies.chat.adapter = adapter + require("codecompanion").config.strategies.inline.adapter = adapter + + vim.notify(string.format("Switched to %s model", model), vim.log.levels.INFO) + + -- Refresh lualine to update the status + pcall(require("lualine").refresh) + end, { + nargs = 1, + complete = function() + return {"sonnet", "opus"} + end, + desc = "Switch CodeCompanion model (sonnet/opus)" + }) + -- Additional keymaps for Opus vim.api.nvim_set_keymap( "n", diff --git a/lua/shelbybark/plugins/lualine.lua b/lua/shelbybark/plugins/lualine.lua index 0dc3303..0e496b4 100644 --- a/lua/shelbybark/plugins/lualine.lua +++ b/lua/shelbybark/plugins/lualine.lua @@ -66,26 +66,74 @@ return { ['t'] = 'TERMINAL', } - -- Better CodeCompanion status function + -- Enhanced CodeCompanion status function with model display local function codecompanion_status() local ok, codecompanion = pcall(require, "codecompanion") if not ok then return "" end - -- Check for active chats or requests - local status = codecompanion.status() - if status and status ~= "" then - return "🤖" + -- 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 - -- Also check if there are any active chat buffers - local chat_ok, chat = pcall(codecompanion.buf_get_chat) - if chat_ok and chat then - return "💬" + -- 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 - - return "" + + -- 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 colors = {