Our AI integration setup optimized for local-first development
-- Primary adapter: Ollama with Llama 3.1 70B
adapters = {
ollama = function()
return require("codecompanion.adapters").extend("ollama", {
name = "llama3.1:70b",
schema = {
model = {
default = "llama3.1:70b",
},
},
})
end,
}
-- All strategies default to local Ollama
strategies = {
chat = {
adapter = "ollama", -- Local Llama 3.1 70B
},
inline = {
adapter = "ollama", -- For inline assistance
},
agent = {
adapter = "ollama", -- For agent workflows
},
}
-- Located in: src/neovim/plugins.lua
prompts = {
-- Industry style guide compliance
["Style Review"] = {
strategy = "chat",
description = "Review for industry style guide compliance",
opts = {
index = 10,
default_prompt = [[
Review this code for industry style guide compliance.
Focus on:
- Naming conventions
- Documentation standards
- Code organization
- Language-specific guidelines
]],
},
},
-- Performance optimization
["Performance Review"] = {
strategy = "chat",
description = "Analyze performance characteristics",
opts = {
index = 11,
default_prompt = [[
Analyze this code for performance:
- Time complexity
- Space complexity
- Potential bottlenecks
- Optimization opportunities
Consider production scale.
]],
},
},
}
-- Automatically include git context
opts = {
send_code = true,
use_default_prompt_library = true,
-- Custom context function
context = function()
local git_diff = vim.fn.system("git diff --cached")
return git_diff ~= "" and git_diff or nil
end,
}
-- Smart file inclusion based on project type
slash_commands = {
["project"] = {
callback = function()
-- Include relevant project files
local ft = vim.bo.filetype
if ft == "python" then
return { "requirements.txt", "setup.py", "pyproject.toml" }
elseif ft == "javascript" then
return { "package.json", "tsconfig.json" }
end
end
}
}
-- Our visual mode mappings
keymaps = {
["<leader>ce"] = "explain", -- Detailed explanation
["<leader>ct"] = "tests", -- Generate tests
["<leader>cf"] = "fix", -- Fix issues
["<leader>co"] = "optimize", -- Performance optimization
["<leader>cr"] = "review", -- Code review
["<leader>cs"] = "security", -- Security audit (custom)
}
-- Enhanced chat experience
display = {
chat = {
window = {
width = 0.4, -- 40% of screen
height = 0.8, -- 80% height
border = "rounded",
},
-- Custom highlighting
highlights = {
user = "CodeCompanionUser",
assistant = "CodeCompanionAssistant",
},
},
}
-- Optimized for responsive feedback
opts = {
stream = true,
-- Faster token generation
stream_callback = function(chunk)
-- Process incrementally
vim.schedule(function()
-- Update UI without blocking
end)
end,
}
-- Prevent context overflow
pre_req = function(adapter, messages)
-- Limit context to relevant code
local max_tokens = 4000
local current_tokens = 0
for i = #messages, 1, -1 do
current_tokens = current_tokens + #messages[i].content
if current_tokens > max_tokens then
-- Truncate older messages
messages = vim.list_slice(messages, i + 1)
break
end
end
return messages
end
# Recommended models for coding
ollama pull codellama:13b # Best for code completion
ollama pull llama3.2:latest # General purpose
ollama pull deepseek-coder:6.7b # Smaller, faster
-- Ollama-specific optimizations
adapters = {
ollama = {
parameters = {
num_gpu = 1, -- Use GPU if available
num_thread = 8, -- CPU threads
repeat_penalty = 1.1, -- Reduce repetition
mirostat = 2, -- Better coherence
}
}
}
:checkhealth codecompanion
-- Test specific adapter
:CodeCompanion adapter=ollama "Test prompt"
-- Check adapter status
:lua print(vim.inspect(require('codecompanion').get_adapter('ollama')))
# Enable debug logging
export CODECOMPANION_LOG_LEVEL=debug
# View logs
tail -f ~/.local/state/nvim/codecompanion.log
-- Find and include files via Telescope
["<leader>caf"] = function()
require('telescope.builtin').find_files({
attach_mappings = function(_, map)
map('i', '<CR>', function(prompt_bufnr)
-- Include selected file in context
local selection = require('telescope.actions.state').get_selected_entry()
require('codecompanion').add_context(selection.path)
end)
return true
end,
})
end
-- Generate and insert snippets
["<leader>cg"] = function()
require('codecompanion').generate({
strategy = "inline",
adapter = "ollama",
prompt = "Generate a snippet for: " .. vim.fn.input("Snippet: "),
callback = function(snippet)
require('luasnip').snip_expand(snippet)
end,
})
end